feat: surface network errors via a Result wrapper and shared callback - #918
Open
sinful1992 wants to merge 1 commit into
Open
feat: surface network errors via a Result wrapper and shared callback#918sinful1992 wants to merge 1 commit into
sinful1992 wants to merge 1 commit into
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
Author
Repository requests used anonymous Retrofit callbacks whose onFailure was almost always empty and whose non-2xx responses were ignored, so a failed request left the UI on an empty list or an endless shimmer with no message. Introduce the shared mechanism the incremental rollout can build on: - Resource<T> (Loading/Success/Error) plus a categorised NetworkError (UNREACHABLE / SERVER_ERROR / INVALID_RESPONSE / AUTH_FAILED / API_ERROR), so a caller can tell "wrong credentials" from "server unreachable" from "server returned garbage" — exactly what the hardened login flow (eddyizm#829) needs. - SubsonicCallback<T>, one Retrofit adapter that maps transport failure, non-2xx, unparseable body and a "failed" Subsonic response into a Resource in a single place; subclasses only extract the payload they need. Wire the login credential check as the first consumer: checkUserCredential now reports a Resource, and LoginFragment shows a specific message per error category instead of a raw exception string. The other ~95 repository callsites are intentionally left for incremental follow-up. ErrorCode constants become `const val` so they are usable from Java. Closes eddyizm#912
sinful1992
force-pushed
the
feat/surface-network-errors
branch
from
July 21, 2026 22:14
c4675d7 to
c9082c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #912 (split out from #858).
Problem
Repositories use anonymous Retrofit callbacks whose
onFailureis almost always empty (or a bareLog.d), and non-2xx responses inonResponseare ignored. When a request fails the LiveData never updates, so the user sees an empty list or an endless shimmer with no message and no way to tell why — a likely contributor to reports like #853.Change
This ships the mechanism the issue describes, plus one real consumer, so the rollout to the other repositories can happen incrementally without a 90-file mega-PR.
Mechanism (
subsonic/base/):Resource<T>— Loading / Success / Error.NetworkError— a categorised failure:UNREACHABLE(transport),SERVER_ERROR(non-2xx),INVALID_RESPONSE(2xx but missing/unparseable body),AUTH_FAILED(Subsonicfailedwith a credential/authorization code),API_ERROR(any otherfailed). This is the distinction a hardened login needs: wrong credentials vs server unreachable vs server returned garbage.SubsonicCallback<T>— one Retrofit adapter that maps all of the above into aResourcein a single place; subclasses only implementextractData(SubsonicResponse). This is what removes the duplicated anonymous-callback boilerplate as callsites migrate.First consumer — the login credential check:
SystemRepository.checkUserCredentialnow reports aResource<Void>.LoginFragmentshows a specific message per category (wrong credentials / couldn't reach server / server error / unexpected response) instead of a raw exception string.SystemCallbackinterface is removed.ErrorCode's constants are changed fromvartoconst valso they're usable from Java (they were previously unreferenced).Deliberately out of scope
The other ~95
enqueuecallsites are not touched — they're the incremental follow-up the issue calls for. This PR keeps the diff reviewable and proves the mechanism end-to-end on the path #829 most needs it.Milestone placement
Per the #858 thread, @eddyizm noted Tom may want to decide where this lands. It's broader than login (it's repository-wide infrastructure) but the login flow is its first consumer, matching the "build it first with
LoginActivityas first consumer" plan in #829. Flagging for you both to slot as you see fit.Testing
Not build-verified locally (no build env set up here) — CI/maintainer build appreciated. The login path is exercised by the existing server-tap flow; error categories map straight from Retrofit/Subsonic responses.