mirror of
https://github.com/readrops/Readrops.git
synced 2025-01-31 19:05:07 +01:00
Improve http errors wording
This commit is contained in:
parent
f14ed7f331
commit
e9536e99ed
@ -37,7 +37,7 @@ import cafe.adriel.voyager.navigator.currentOrThrow
|
|||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import com.readrops.app.compose.home.HomeScreen
|
import com.readrops.app.compose.home.HomeScreen
|
||||||
import com.readrops.app.compose.util.components.AndroidScreen
|
import com.readrops.app.compose.util.components.AndroidScreen
|
||||||
import com.readrops.app.compose.util.components.errorText
|
import com.readrops.app.compose.util.ErrorMessage
|
||||||
import com.readrops.app.compose.util.theme.ShortSpacer
|
import com.readrops.app.compose.util.theme.ShortSpacer
|
||||||
import com.readrops.app.compose.util.theme.VeryLargeSpacer
|
import com.readrops.app.compose.util.theme.VeryLargeSpacer
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
import com.readrops.app.compose.util.theme.spacing
|
||||||
@ -178,7 +178,7 @@ class AccountCredentialsScreen(
|
|||||||
ShortSpacer()
|
ShortSpacer()
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = errorText(exception = state.loginException!!),
|
text = ErrorMessage.get(exception = state.loginException!!),
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
|
@ -13,8 +13,8 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import com.readrops.app.compose.repositories.ErrorResult
|
import com.readrops.app.compose.repositories.ErrorResult
|
||||||
|
import com.readrops.app.compose.util.ErrorMessage
|
||||||
import com.readrops.app.compose.util.components.BaseDialog
|
import com.readrops.app.compose.util.components.BaseDialog
|
||||||
import com.readrops.app.compose.util.components.errorText
|
|
||||||
import com.readrops.app.compose.util.theme.MediumSpacer
|
import com.readrops.app.compose.util.theme.MediumSpacer
|
||||||
import com.readrops.app.compose.util.theme.ShortSpacer
|
import com.readrops.app.compose.util.theme.ShortSpacer
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ fun ErrorListDialog(
|
|||||||
modifier = Modifier.verticalScroll(scrollableState)
|
modifier = Modifier.verticalScroll(scrollableState)
|
||||||
) {
|
) {
|
||||||
for (error in errorResult.entries) {
|
for (error in errorResult.entries) {
|
||||||
Text(text = "${error.key.name}: ${errorText(error.value)}")
|
Text(text = "${error.key.name}: ${ErrorMessage.get(error.value)}")
|
||||||
|
|
||||||
ShortSpacer()
|
ShortSpacer()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.readrops.app.compose.util
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.readrops.api.utils.exceptions.HttpException
|
||||||
|
import com.readrops.api.utils.exceptions.ParseException
|
||||||
|
import com.readrops.api.utils.exceptions.UnknownFormatException
|
||||||
|
import com.readrops.app.compose.R
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
|
object ErrorMessage {
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun get(exception: Exception) = when (exception) {
|
||||||
|
is HttpException -> getHttpMessage(exception)
|
||||||
|
is UnknownHostException -> stringResource(R.string.unreachable_url)
|
||||||
|
is NoSuchFileException -> stringResource(R.string.unable_open_file)
|
||||||
|
is IOException -> stringResource(R.string.network_failure, exception.message.orEmpty())
|
||||||
|
is ParseException, is UnknownFormatException -> stringResource(R.string.processing_feed_error)
|
||||||
|
else -> "${exception.javaClass.simpleName}: ${exception.message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun getHttpMessage(exception: HttpException): String {
|
||||||
|
return when (exception.code) {
|
||||||
|
in 400..499 -> {
|
||||||
|
when (exception.code) {
|
||||||
|
400 -> stringResource(id = R.string.http_error_400)
|
||||||
|
401 -> stringResource(id = R.string.http_error_401)
|
||||||
|
403 -> stringResource(id = R.string.http_error_403)
|
||||||
|
404 -> stringResource(id = R.string.http_error_404)
|
||||||
|
else -> stringResource(id = R.string.http_error_4XX, exception.code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in 500..599 -> {
|
||||||
|
stringResource(id = R.string.http_error_5XX, exception.code)
|
||||||
|
}
|
||||||
|
else -> stringResource(id = R.string.http_error, exception.code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,12 +4,8 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.readrops.api.utils.exceptions.HttpException
|
|
||||||
import com.readrops.api.utils.exceptions.ParseException
|
|
||||||
import com.readrops.api.utils.exceptions.UnknownFormatException
|
|
||||||
import com.readrops.app.compose.R
|
import com.readrops.app.compose.R
|
||||||
import java.io.IOException
|
import com.readrops.app.compose.util.ErrorMessage
|
||||||
import java.net.UnknownHostException
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ErrorDialog(
|
fun ErrorDialog(
|
||||||
@ -21,17 +17,7 @@ fun ErrorDialog(
|
|||||||
icon = painterResource(id = R.drawable.ic_error),
|
icon = painterResource(id = R.drawable.ic_error),
|
||||||
onDismiss = onDismiss
|
onDismiss = onDismiss
|
||||||
) {
|
) {
|
||||||
Text(text = errorText(exception = exception))
|
Text(text = ErrorMessage.get(exception = exception))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check compatibility with other accounts errors
|
|
||||||
@Composable
|
|
||||||
fun errorText(exception: Exception) = when (exception) {
|
|
||||||
is HttpException -> stringResource(id = R.string.unreachable_feed_http_error, exception.code.toString())
|
|
||||||
is UnknownHostException -> stringResource(R.string.unreachable_feed)
|
|
||||||
is NoSuchFileException -> stringResource(R.string.unable_open_file)
|
|
||||||
is IOException -> stringResource(R.string.network_failure, exception.message.orEmpty())
|
|
||||||
is ParseException, is UnknownFormatException -> stringResource(R.string.processing_feed_error)
|
|
||||||
else -> "${exception.javaClass.simpleName}: ${exception.message}"
|
|
||||||
}
|
|
@ -155,6 +155,13 @@
|
|||||||
<string name="unreachable_feed_http_error">Flux non attaignable, erreur HTTP %1$s</string>
|
<string name="unreachable_feed_http_error">Flux non attaignable, erreur HTTP %1$s</string>
|
||||||
<string name="network_failure">Erreur réseau: %1$s</string>
|
<string name="network_failure">Erreur réseau: %1$s</string>
|
||||||
<string name="processing_feed_error">Erreur de traitement du flux</string>
|
<string name="processing_feed_error">Erreur de traitement du flux</string>
|
||||||
<string name="unreachable_feed">Flux non attaignable</string>
|
<string name="unreachable_url">URL non attaignable</string>
|
||||||
<string name="unable_open_file">Impossible d\'ouvrir le fichier</string>
|
<string name="unable_open_file">Impossible d\'ouvrir le fichier</string>
|
||||||
|
<string name="http_error_400">Erreur HTTP 400, veuillez vérifier l\'URL du serveur</string>
|
||||||
|
<string name="http_error_401">Erreur HTTP 401, veuillez vérifier vos identifiants</string>
|
||||||
|
<string name="http_error_403">Erreur HTTP 403, accès interdit</string>
|
||||||
|
<string name="http_error_404">Erreur HTTP 404, l\'URL n\'existe pas</string>
|
||||||
|
<string name="http_error_4XX">Erreur HTTP %1$s, veuillez vérifier vos champs</string>
|
||||||
|
<string name="http_error_5XX">Erreur HTTP %1$s, erreur serveur</string>
|
||||||
|
<string name="http_error">Erreur HTTP %1$s</string>
|
||||||
</resources>
|
</resources>
|
@ -161,6 +161,13 @@
|
|||||||
<string name="unreachable_feed_http_error">Unreachable feed, HTTP error %1$s</string>
|
<string name="unreachable_feed_http_error">Unreachable feed, HTTP error %1$s</string>
|
||||||
<string name="network_failure">Network failure: %1$s</string>
|
<string name="network_failure">Network failure: %1$s</string>
|
||||||
<string name="processing_feed_error">Processing feed error</string>
|
<string name="processing_feed_error">Processing feed error</string>
|
||||||
<string name="unreachable_feed">Unreachable feed</string>
|
<string name="unreachable_url">Unreachable URL</string>
|
||||||
<string name="unable_open_file">Unable to open file</string>
|
<string name="unable_open_file">Unable to open file</string>
|
||||||
|
<string name="http_error_400">HTTP error 400, please check your server URL</string>
|
||||||
|
<string name="http_error_401">HTTP error 401, please check your credentials</string>
|
||||||
|
<string name="http_error_403">HTTP error 403, access forbidden</string>
|
||||||
|
<string name="http_error_404">HTTP error 404, URL not found</string>
|
||||||
|
<string name="http_error_4XX">HTTP error %1$s, please check your fields</string>
|
||||||
|
<string name="http_error_5XX">HTTP error %1$s, server error</string>
|
||||||
|
<string name="http_error">HTTP error %1$s</string>
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user