-
Notifications
You must be signed in to change notification settings - Fork 321
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
Error messages are not returned #875
Comments
This seems to be a relatively common confusion - because the I believe @Fishrock123 has a logging middleware that deals with this as well (for json response errors) so it would be nice to re-evaluate error handling and maybe make that a part of the tide core. |
@mdtusz this is half true. To be more accurate: given the above code, the status code is indeed 400. But the body is empty. So I'm confused, why the first argument "leaks through" but not the second? Express used to support this code: res.send(400, "Validation failed ..."); and On the other side, and I didn't think about it before I wrote it on my previous message, Ok(Response::builder(StatusCode::BadRequest).body("Validation failed ...").into()) which is FWIW close to the actual express equivalent: res.status(400).send("Validation failed ..."); If Another fallacy is that it's easier to early return |
I've finally found the error handling example. However I'm not fan of dynamic casts. I prefer to send upfront the proper response, rather than relying on post-process transform. Another issue I stumbled across is that, while handlers are added through objects implementing I imagine two solutions:
Both could be done, but for solving my issue, I prefer having the latter only. It's such a tiny change and I think it's not a breaking change. What do you think about that? |
Agreed it feels a bit strange matching on an error and converting it back into an @jbr @Fishrock123 thoughts on the comments above? I know there's a few issues (and maybe PR's) open around error handling so may be good to consolidate them and re-evaluate options on a way to address some concerns. The second suggestion seems reasonable to me, but I could imagine this causing issues for some existing middlewares that are out there. It would definitely be very useful to be able to return custom domain-specific error types that can be converted into a proper http error response though (without having to write a specific case in a middleware handler for each). |
I think this is a @yoshuawuyts question. My personal opinion is that handlers should necessarily return Response, but that's not at all tide's design. Unless Yosh says otherwise, my guess is that tide's design will remain exactly as it is currently until the language changes |
Hi,
Given the following app:
POST requests will fail, but the error message won't be sent. I expect that they should, because they can contain valuable information, e.g. related to validation failures. I've seen no mechanism to switch that. Note that I'm developing an API, so responses can be brief, of course for a public-facing 404 error page it makes sense to have an actual Response with some HTML template.
Perhaps such messages shouldn't be
Err
butOk
values, but then, why doError::from_str
take these two arguments where only the former is taken into account?FWIW I've done several servers in NodeJS with express, and I find this library to have sensible default behaviors, which is to display the error message, adding details (stacktrace) only in development environment, and all of that can be overridden by error middlewares. I haven't seen these features in Tide, what do you think about them?
The text was updated successfully, but these errors were encountered: