Merge branch 'fix_offline_server' into 'master'

Offline server no longer makes app crash

Closes #357

See merge request pixeldroid/PixelDroid!524
This commit is contained in:
Matthieu 2023-01-07 11:26:07 +00:00
commit 3d0ec86ac7
2 changed files with 9 additions and 2 deletions

View File

@ -1,7 +1,6 @@
package org.pixeldroid.app.posts.feeds
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import androidx.constraintlayout.motion.widget.MotionLayout
@ -83,7 +82,14 @@ internal fun <T: Any> initAdapter(
?: loadState.refresh as? LoadState.Error
errorState?.let {
val error: String = (it.error as? HttpException)?.response()?.errorBody()?.string()?.ifEmpty { null }?.let { s ->
Gson().fromJson(s, org.pixeldroid.app.utils.api.objects.Error::class.java)?.error?.ifBlank { null }
try {
Gson().fromJson(s, org.pixeldroid.app.utils.api.objects.Error::class.java)?.error?.ifBlank { null }
} catch (exception: Exception) {
errorLayout.root.context.getString(
R.string.unknown_error_in_error,
it.error.localizedMessage.orEmpty()
)
}
} ?: it.error.localizedMessage.orEmpty()
showError(motionLayout = motionLayout, errorLayout = errorLayout, errorText = error)
}

View File

@ -123,6 +123,7 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<!-- Loading error messages -->
<string name="loading_toast">Something went wrong while loading</string>
<string name="feed_failed">Could not get feed</string>
<string name="unknown_error_in_error">Unknown error, check if server is down: %1$s</string>
<!-- Post pop-up options -->
<string name="share_picture">Share picture…</string>
<string name="save_to_gallery">Save to Gallery…</string>