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

View file

@ -81,7 +81,7 @@ class SharedItemsViewModel @Inject constructor(
}
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() {