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 } }