Hello, I am writing a Plugin in Ktor, the idea of ...
# ktor
d
Hello, I am writing a Plugin in Ktor, the idea of this Plugin is to first check if Internet is available, if not cancel request and throw error, and when we receive response we check if the status is
401
in that case retry the call after making a new token.
Copy code
scope.requestPipeline.intercept(HttpRequestPipeline.State) {
    println("MyNewPlugin : works the scope ${context.method}")
    context.header(HttpHeaders.UserAgent, feature.agent)
}
scope.responsePipeline.intercept(HttpRequestPipeline.State) {
    println("MyNewPlugin : works the scope ${context.response.status}")
}
I wrote this in the
install
function to test the Plugin for request and response pipeline but it crashes with this error
Copy code
Caused by: io.ktor.util.pipeline.InvalidPhaseException: Phase Phase('State') was not registered for this pipeline
a
The second interceptor should be on the phase
HttpResponsePipeline.State
instead of
HttpRequestPipeline.State
because the response pipeline is intercepted.
🙏 1