-
-
Save thomaskioko/a7fd6dc8dc1207f7cf2e9f576b57e998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpClient(httpClientEngine) { | |
expectSuccess = true | |
... | |
HttpResponseValidator { | |
validateResponse { response -> | |
if (!response.status.isSuccess()) { | |
val httpFailureReason = when (response.status) { | |
HttpStatusCode.Unauthorized -> "Unauthorized request" | |
HttpStatusCode.Forbidden -> "${response.status.value} Missing API key" | |
HttpStatusCode.NotFound -> "Invalid Request" | |
HttpStatusCode.UpgradeRequired -> "Upgrade to VIP" | |
HttpStatusCode.RequestTimeout -> "Network Timeout" | |
in HttpStatusCode.InternalServerError..HttpStatusCode.GatewayTimeout -> "${response.status.value} Server Error" | |
else -> "Network error!" | |
} | |
throw HttpExceptions( | |
response = response, | |
cachedResponseText = response.bodyAsText(), | |
httpFailureReason = httpFailureReason, | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment