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