don't crash on unexpected json responses (#3635)
This commit is contained in:
commit
7016fa3abc
4 changed files with 15 additions and 2 deletions
|
@ -332,7 +332,7 @@ class AccountListFragment :
|
||||||
|
|
||||||
val linkHeader = response.headers()["Link"]
|
val linkHeader = response.headers()["Link"]
|
||||||
onFetchAccountsSuccess(accountList, linkHeader)
|
onFetchAccountsSuccess(accountList, linkHeader)
|
||||||
} catch (exception: IOException) {
|
} catch (exception: Exception) {
|
||||||
onFetchAccountsFailure(exception)
|
onFetchAccountsFailure(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.keylesspalace.tusky.components.timeline.util
|
package com.keylesspalace.tusky.components.timeline.util
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
fun Throwable.isExpected() = this is IOException || this is HttpException
|
fun Throwable.isExpected() = this is IOException || this is HttpException || this is JsonParseException
|
||||||
|
|
||||||
inline fun <T> ifExpected(
|
inline fun <T> ifExpected(
|
||||||
t: Throwable,
|
t: Throwable,
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky.components.timeline.viewmodel
|
package com.keylesspalace.tusky.components.timeline.viewmodel
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.paging.ExperimentalPagingApi
|
import androidx.paging.ExperimentalPagingApi
|
||||||
import androidx.paging.LoadType
|
import androidx.paging.LoadType
|
||||||
import androidx.paging.PagingState
|
import androidx.paging.PagingState
|
||||||
|
@ -117,6 +118,7 @@ class CachedTimelineRemoteMediator(
|
||||||
return MediatorResult.Success(endOfPaginationReached = statuses.isEmpty())
|
return MediatorResult.Success(endOfPaginationReached = statuses.isEmpty())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return ifExpected(e) {
|
return ifExpected(e) {
|
||||||
|
Log.w(TAG, "Failed to load timeline", e)
|
||||||
MediatorResult.Error(e)
|
MediatorResult.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,4 +177,8 @@ class CachedTimelineRemoteMediator(
|
||||||
}
|
}
|
||||||
return overlappedStatuses
|
return overlappedStatuses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "CachedTimelineRM"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky.components.timeline.viewmodel
|
package com.keylesspalace.tusky.components.timeline.viewmodel
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.paging.ExperimentalPagingApi
|
import androidx.paging.ExperimentalPagingApi
|
||||||
import androidx.paging.LoadType
|
import androidx.paging.LoadType
|
||||||
import androidx.paging.PagingState
|
import androidx.paging.PagingState
|
||||||
|
@ -106,8 +107,13 @@ class NetworkTimelineRemoteMediator(
|
||||||
return MediatorResult.Success(endOfPaginationReached = statuses.isEmpty())
|
return MediatorResult.Success(endOfPaginationReached = statuses.isEmpty())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return ifExpected(e) {
|
return ifExpected(e) {
|
||||||
|
Log.w(TAG, "Failed to load timeline", e)
|
||||||
MediatorResult.Error(e)
|
MediatorResult.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "NetworkTimelineRM"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue