From 4fba36d5392e89a876670948aa10bed5d04e8131 Mon Sep 17 00:00:00 2001 From: Filipe Belatti Date: Sun, 22 Dec 2024 19:39:17 +0000 Subject: [PATCH] Update Linkding bad request handling --- .../com/fibelatti/pinboard/core/di/modules/LinkdingModule.kt | 2 ++ .../features/posts/presentation/EditPostViewModel.kt | 5 +++-- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/core/di/modules/LinkdingModule.kt b/app/src/main/kotlin/com/fibelatti/pinboard/core/di/modules/LinkdingModule.kt index 36b199b9..b44fb250 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/core/di/modules/LinkdingModule.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/core/di/modules/LinkdingModule.kt @@ -44,6 +44,8 @@ object LinkdingModule { accept(ContentType.Application.Json) } + expectSuccess = true + install(unauthorizedPluginProvider.plugin) } } diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/posts/presentation/EditPostViewModel.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/posts/presentation/EditPostViewModel.kt index 554cfd9c..f8ae9fc8 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/posts/presentation/EditPostViewModel.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/posts/presentation/EditPostViewModel.kt @@ -15,6 +15,8 @@ import com.fibelatti.pinboard.features.posts.domain.usecase.AddPost import com.fibelatti.pinboard.features.posts.domain.usecase.InvalidUrlException import com.fibelatti.pinboard.features.tags.domain.model.Tag import dagger.hilt.android.lifecycle.HiltViewModel +import io.ktor.client.plugins.ClientRequestException +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -34,7 +36,6 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.withIndex import kotlinx.coroutines.launch -import javax.inject.Inject @HiltViewModel class EditPostViewModel @Inject constructor( @@ -111,7 +112,7 @@ class EditPostViewModel @Inject constructor( currentState.copy(isLoading = false) } when (error) { - is InvalidUrlException -> { + is InvalidUrlException, is ClientRequestException -> { _screenState.update { currentState -> currentState.copy( invalidUrlError = resourceProvider.getString(R.string.validation_error_invalid_url), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3cf0c846..97b28e66 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -130,7 +130,7 @@ The URL cannot be empty - The URL is invalid + The URL is not accepted by the service The URL could not be saved. Please verify that it is valid The title cannot be empty