-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a general error handler which handles multiple errors - Nia 1435 #1461
base: main
Are you sure you want to change the base?
Conversation
app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt
Outdated
Show resolved
Hide resolved
Removed all but the message.stateIn from AppState Added interface and implementation, dependency injection
Moved error handling responsibilities to a delegate implementation, and then added dependency injection for app and testing. Now, this more closely resembles the implementation of the offline status, and is more generalized and reusable as a message handler. Delegation seemed more appropriate than passing an instance to avoid exposing that instance or redeclaring the add/remove message functions. |
Updated tests to match
How about integrating the snackbars related to Bookmark and Network statuses as well? |
Include OFFLINE message in list of messages, with precedence over other messages. Pass offline value to state for use in other purposes. Include action handling for success/failure to click snackbar button. Implementation of Bookmark UNDO function. Moved implementations of onShowSnackbar and errorHandler closer to use case, removed unnecessary passed down parameters.
Updated the implementation with Bookmarks and Network statuses. @yongsuk44 can you describe more what you mean about the object managing error types? |
Fixes #1435
Fixes #1068
Added error messages to AppState to be displayed via Snackbar ( per this conversation ), and implementation for the custom tab launch failed error as described.
Also added simple tests for error list order functionality.
Now, the errorHandler can be passed to the Route level from NiaApp, and define specific errors to pass at the Screen level. This could be implemented on a per screen/viewmodel basis, but this works as a single source of truth for snackbar-bound errors.
LaunchedEffect on first error message, which prevents flickering from the LaunchedEffect when modifying the list of messages.
ErrorMessage data class for IDs, which prevents duplicate messages from preventing the LaunchedEffect firing.
I will be curious if there is a specific flow based solution to this issue.
The Offline message is still a separate Launched effect due to the value, however the snackbar handles the interaction at that point, so I believe this is the intended approach for general errors.