-
Notifications
You must be signed in to change notification settings - Fork 464
Description
What version are you currently using?
2.1.2
What would you like to see?
First of all, I'm not entirely sure if this issue belongs in this repository or in the Ktor one. Please feel free to close it if it's out of scope for Arrow.
In Ktor, the StatusPages plugin allows centralized exception handling by automatically detecting exceptions:
install(StatusPages) {
exception<Throwable> { call, cause ->
call.respondText(text = "500: $cause" , status = HttpStatusCode.InternalServerError)
}
}A similar mechanism could be incredibly helpful when using Arrow’s typed errors.
Currently, all errors must be handled locally (here's an example I found online), which often leads to writing custom boilerplate to maintain the DRY principle.
A centralized way to handle typed errors would be highly practical especially in web applications as in this case, since strong typing could enable straightforward HTTP status code mapping.
The code that follows would be a dream of mine, though I'm unsure whether it's really feasible or how complex it would be to implement:
install(StatusPages) {
recover<UserNotFound> { call, error ->
call.respondText(text = "404: $error" , status = HttpStatusCode.NotFound)
}
}I'm aware there may be significant limitations to making this kind of integration possible, particularly because the Ktor API is designed to be agnostic and shouldn't depend on the presence of Arrow constructs. That said, if this feature is of interest to the community, even a suboptimal solution could be greatly appreciated!
Thank you so much for all your work!