Is there a hook to for client plugins to capture e...
# ktor
a
Is there a hook to for client plugins to capture exceptions such as UnknownHost or SocketReadTimeout for monitoring purposes? I dont see any method in the Tracer plugin nor any hook on the Monitoring events
o
Didn't try, but would it work with
HttpCallValidator
? https://ktor.io/docs/client-response-validation.html
I just tried, with
expectSuccess=true
& a custom validator, I get
java.nio.channels.UnresolvedAddressException
, when no Internet connection.
Same thing without
expectSuccess=true
a
I already have a HttpCallValidator, not sure how the ordering works when 2+ plugins use the same phase in the pipeline. is that documented anywhere / is there a way to log the order of the phases?
a
You can intercept the
Monitoring
phase of the
HttpSendPipeline
and use
proceed
to catch any exceptions thrown during the call. Here is an example:
Copy code
val client = HttpClient(CIO) {}

client.sendPipeline.intercept(HttpSendPipeline.Monitoring) {
    try {
        proceed()
    } catch (t: UnresolvedAddressException) {
        println("Caught exception: $t")
        throw t
    }
}

client.get("<http://nonexistent1234.com>")
🙏 1