From 6bdcc2d15c16511e65bc79a4c89aeddbe1acd843 Mon Sep 17 00:00:00 2001 From: Fabian Schedler Date: Sat, 20 Jul 2024 21:58:07 +0200 Subject: [PATCH] fix: invalid token & better error messages --- .../mediator/core/api/ApiExceptionTransformer.kt | 7 +++++-- .../waiterrobot/mediator/core/api/AuthorizedHttpClient.kt | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/ApiExceptionTransformer.kt b/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/ApiExceptionTransformer.kt index 51e7dd4..905b9b4 100644 --- a/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/ApiExceptionTransformer.kt +++ b/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/ApiExceptionTransformer.kt @@ -11,7 +11,7 @@ import org.datepollsystems.waiterrobot.mediator.data.api.ApiException fun HttpClientConfig<*>.installApiClientExceptionTransformer(json: Json, logger: Logger) { expectSuccess = true HttpResponseValidator { - handleResponseExceptionWithRequest { exception, _ -> + handleResponseExceptionWithRequest { exception, request -> val clientException = exception as? ClientRequestException ?: return@handleResponseExceptionWithRequest @@ -21,7 +21,10 @@ fun HttpClientConfig<*>.installApiClientExceptionTransformer(json: Json, logger: throw try { json.decodeFromString(jsonString) } catch (e: SerializationException) { - logger.w(e) { "Could not serialize ClientError using fallback" } + logger.w(e) { + "Could not serialize ClientError using fallback.\n" + + "\t(${request.method.value}: ${request.url}, ${clientException.response.status} '$jsonString')" + } try { json.decodeFromString(jsonString) } catch (_: SerializationException) { diff --git a/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/AuthorizedHttpClient.kt b/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/AuthorizedHttpClient.kt index c5d994e..3093582 100644 --- a/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/AuthorizedHttpClient.kt +++ b/src/main/kotlin/org/datepollsystems/waiterrobot/mediator/core/api/AuthorizedHttpClient.kt @@ -35,6 +35,7 @@ fun HttpClientConfig<*>.configureAuth(enableNetworkLogs: Boolean, logger: Logger } catch (e: Exception) { // TODO improve request errors handling (-> try again, logout?, no connection info) logger.e(e) { "Error while refreshing token: ${e.message}" } + App.logout() null } }