Sam Garfinkel
04/21/2020, 7:56 PMrharter
04/22/2020, 12:49 AMSam Garfinkel
04/22/2020, 2:02 PMrharter
04/22/2020, 3:55 PMSam Garfinkel
04/22/2020, 3:56 PMe5l
04/22/2020, 4:09 PMproceed
or proceedWith
method with try catch
and it will give you the exception!Sam Garfinkel
04/22/2020, 4:10 PMoverride fun install(feature: RetryOnFailure, scope: HttpClient) {
scope.receivePipeline.intercept(HttpReceivePipeline.Before) {
proceedWith(it)
throw RuntimeException()
}
scope.receivePipeline.intercept(HttpReceivePipeline.After) {
try {
proceedWith(it)
} catch (e: Exception) {
println("Hello world")
e.printStackTrace()
}
}
}
e5l
04/22/2020, 4:11 PMBefore
to After
, so the Before
will receive the exception thrown in After
Sam Garfinkel
04/22/2020, 4:13 PMe5l
04/22/2020, 4:14 PMSam Garfinkel
04/22/2020, 4:15 PMBeforeReceive
phase. Somehow I’ll need to figure out how to insert even before that.e5l
04/22/2020, 4:16 PMPipeline
has special methods to insert phase before and after. So you can create a new phase, insert it, and then intercept.Sam Garfinkel
04/22/2020, 4:17 PMHttpResponsePipeline
and HttpReceivePipeline
?e5l
04/22/2020, 4:19 PMSam Garfinkel
04/22/2020, 4:20 PMjava.lang.ClassCastException: class io.ktor.client.utils.EmptyContent cannot be cast to class io.ktor.client.call.HttpClientCall
when a timeout occurs (via the Timeout
feature). Here’s the configuration that causes this:
val handleValidation = PipelinePhase("HandleValidation")
scope.requestPipeline.insertPhaseBefore(HttpRequestPipeline.Before, handleValidation)
scope.requestPipeline.intercept(handleValidation) {
repeat(5) {
try {
proceed()
} catch (e: Exception) {
delay(100)
println("retry attempt: $it")
}
}
}
proceed()
multiple times from the interceptor above would cause this?