KHttpException
Sealed hierarchy of HTTP-related exceptions thrown by buildKHttpClient.
All subclasses extend Exception and carry a human-readable message parsed from the response body (fields message or error), falling back to the raw body (truncated to 200 chars).
Typical handling:
try {
api.getProducts()
} catch (e: KHttpException.ClientError) {
when (e.statusCode) {
401 -> navigateToLogin()
403 -> showPermissionDenied()
else -> toast("Client error ${e.statusCode}: ${e.message}")
}
} catch (e: KHttpException.ServerError) {
toast("Server error ${e.statusCode}: ${e.message}")
} catch (e: KHttpException.NotAccepted) {
log("Unexpected status: ${e.message}")
}Content copied to clipboard
Inheritors
Types
Link copied to clipboard
Thrown on 4xx responses.
Link copied to clipboard
Thrown by io.ktor.client.statement.HttpResponse.accept when the response status does not match any of the expected io.ktor.http.HttpStatusCodes.
Link copied to clipboard
Thrown on 5xx responses, or with statusCode = -1 for network-level failures (timeout, no connectivity, etc.).