fix: Prevent a ClassCastException when handling timeline errors (#273)

This commit is contained in:
Nik Clayton 2023-11-21 13:48:41 +01:00 committed by GitHub
parent a6a68f1384
commit 806991f8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -414,10 +414,11 @@ class TimelineFragment :
.collect { (loadState, presentationState) ->
when (presentationState) {
PresentationState.ERROR -> {
val message =
(loadState.refresh as LoadState.Error).error.getErrorString(
requireContext(),
)
val error = (loadState.mediator?.refresh as? LoadState.Error)?.error
?: (loadState.source.refresh as? LoadState.Error)?.error
?: IllegalStateException("unknown error")
val message = error.getErrorString(requireContext())
// Show errors as a snackbar if there is existing content to show
// (either cached, or in the adapter), or as a full screen error
@ -433,8 +434,7 @@ class TimelineFragment :
.setAction(R.string.action_retry) { adapter.retry() }
snackbar!!.show()
} else {
val drawableRes =
(loadState.refresh as LoadState.Error).error.getDrawableRes()
val drawableRes = error.getDrawableRes()
binding.statusView.setup(drawableRes, message) {
snackbar?.dismiss()
adapter.retry()