fix error handling for shared items.

Before this with http 406 it threw a NPE and UI was shown as loading state.
With this commit an empty list is returned when there is a http error.

http 406 happens for federated rooms for now. So it might be that Shared items screen will be hidden by additional commits.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-03-20 15:53:39 +01:00
parent 5fead79743
commit 611dcb7911
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 14 additions and 8 deletions

View File

@ -188,15 +188,20 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi, pr
1 1
).map { ).map {
val types = mutableSetOf<SharedItemType>() val types = mutableSetOf<SharedItemType>()
val typeMap = it.body()!!.ocs!!.data!!
for (t in typeMap) { if (it.code() == HTTP_OK) {
if (t.value.isNotEmpty()) { val typeMap = it.body()!!.ocs!!.data!!
try { for (t in typeMap) {
types += SharedItemType.typeFor(t.key) if (t.value.isNotEmpty()) {
} catch (e: IllegalArgumentException) { try {
Log.w(TAG, "Server responds an unknown shared item type: ${t.key}") types += SharedItemType.typeFor(t.key)
} catch (e: IllegalArgumentException) {
Log.w(TAG, "Server responds an unknown shared item type: ${t.key}")
}
} }
} }
} else {
Log.e(TAG, "Failed to getSharedItemsOverview")
} }
types.toSet() types.toSet()
@ -213,6 +218,7 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi, pr
companion object { companion object {
const val BATCH_SIZE: Int = 28 const val BATCH_SIZE: Int = 28
private const val HTTP_OK: Int = 200
private val TAG = SharedItemsRepositoryImpl::class.simpleName private val TAG = SharedItemsRepositoryImpl::class.simpleName
} }
} }

View File

@ -81,7 +81,7 @@ class SharedItemsViewModel @Inject constructor(
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
Log.d(TAG, "An error occurred: $e") Log.e(TAG, "An error occurred when loading available types", e)
} }
override fun onComplete() { override fun onComplete() {