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