Small improvement to error showing
This commit is contained in:
parent
dda06b1cd5
commit
ae54b83ec7
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.DiffUtil
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -80,6 +81,11 @@ internal fun <T: Any> initAdapter(
|
|||
?: loadState.append as? LoadState.Error
|
||||
?: loadState.prepend as? LoadState.Error
|
||||
?: loadState.refresh as? LoadState.Error
|
||||
|
||||
if(errorState?.error is CancellationException){
|
||||
return@addLoadStateListener
|
||||
}
|
||||
|
||||
errorState?.let {
|
||||
val error: String = (it.error as? HttpException)?.response()?.errorBody()?.string()?.ifEmpty { null }?.let { s ->
|
||||
try {
|
||||
|
|
|
@ -47,7 +47,7 @@ class HomeFeedRemoteMediator @Inject constructor(
|
|||
HomeStatusDatabaseEntity(user.user_id, user.instance_uri, it)
|
||||
}
|
||||
|
||||
val endOfPaginationReached = apiResponse.isEmpty()
|
||||
val endOfPaginationReached = apiResponse.isEmpty() || maxId == apiResponse.sortedBy { it.created_at }.last().id
|
||||
|
||||
db.withTransaction {
|
||||
// Clear table in the database
|
||||
|
|
|
@ -62,7 +62,7 @@ class PublicFeedRemoteMediator @Inject constructor(
|
|||
val dbObjects = apiResponse.map{
|
||||
PublicFeedStatusDatabaseEntity(user.user_id, user.instance_uri, it)
|
||||
}
|
||||
val endOfPaginationReached = apiResponse.isEmpty()
|
||||
val endOfPaginationReached = apiResponse.isEmpty() || maxId == apiResponse.sortedBy { it.created_at }.last().id
|
||||
|
||||
db.withTransaction {
|
||||
// Clear table in the database
|
||||
|
|
|
@ -23,6 +23,7 @@ import retrofit2.converter.gson.GsonConverterFactory
|
|||
import retrofit2.http.*
|
||||
import retrofit2.http.Field
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
/*
|
||||
|
@ -51,7 +52,9 @@ interface PixelfedAPI {
|
|||
.client(
|
||||
OkHttpClient().newBuilder().addNetworkInterceptor(headerInterceptor)
|
||||
// Only do secure-ish TLS connections (no HTTP or very old SSL/TLS)
|
||||
.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS)).build()
|
||||
.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS))
|
||||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.build()
|
||||
)
|
||||
.build().create(PixelfedAPI::class.java)
|
||||
}
|
||||
|
@ -74,6 +77,7 @@ interface PixelfedAPI {
|
|||
OkHttpClient().newBuilder().addNetworkInterceptor(headerInterceptor)
|
||||
// Only do secure-ish TLS connections (no HTTP or very old SSL/TLS)
|
||||
.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS))
|
||||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.authenticator(TokenAuthenticator(user, db, pixelfedAPIHolder))
|
||||
.addInterceptor {
|
||||
it.request().newBuilder().run {
|
||||
|
|
Loading…
Reference in New Issue