New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to customize HTTP response error handling #75
Comments
I think RecoveryMiddleware would be fine if we made all of our modules throw errors instead of simply returning a response with a bad status. However, considering how vital error handling is, I think that RecoveryMiddleware should add an extension to RouterBuilder so that one can call the method |
yeah! that's the second part of the solution. protocol Error: ErrorProtocol {
var status: S4.Status { get }
}
enum ClientError: Error {
case badRequest
case unauthorized
case paymentRequired
case forbidden
...
var status: S4.Status {
switch self {
case badRequest: return .badRequest
case unauthorized: return .unauthorized
...
}
}
}
enum ServerError: Error {
case internalServerError
case notImplemented
...
} Then we throw these errors in our modules instead of returning a response, like @Danappelxx said. And as a safety measure. If a user doesn't catch these in a |
Actually, I'd like |
Or we can propose to move this to S4. |
This all sounds good to me. As @Danappelxx said, |
I think we should strive to only return HTTP errors when we're in that scope. maybe add some more information to |
If you want to make some S4 compatible Middleware or Router, etc. You'd have to throw a common error or else something like |
ok I'll create a PR with this in S4. we can continue discussing what properties |
This is possible now. We should inspect where we can throw the HTTP errors and add a default catcher to our HTTP servers. |
For example, HTTPFile.FileResponder simply return a 404 response on any file errors, regardless of whether its permission or the file is just a directory.
I opened a pull request regarding this with a very in-elegant solution.
It looks like Zewo/RecoveryMiddleware gets us halfway there.
The text was updated successfully, but these errors were encountered: