-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
How is the Error type of FromRequest used? #1145
Comments
https://github.com/SergioBenitez/Rocket/blob/master/core/lib/src/request/from_request.rs#L86-L88 seems to indicate that the error type does get used in some way, but I m not able to make the leap to how a catcher would be able to extract/get the |
This looks a lot like #749, but for You can access the error itself in a route by taking |
thanks @jebrosen is there a canonical way/any way to respond to Err results/Failure outcomes where if the type inside the Err/Failure itself is a Responder, it is used to generate the response body? stash it in request local state and pull it out in custom catchers for the status codes in question? Somehow encode it better in a type, and implement a Responder for that type? If I take that Seem like you have to choose between Status and Error when using a request guard, using a |
looks like the request local state stashing + custom catcher things works out. |
We actually do want to support that somehow, but it's effectively blocked on a rust language feature.
In a sense yes: The In the future it might be nice to support things like #[catch(400)]
fn my_errors(error: ErrorType) -> Json<ErrorType> {
Json(error)
} But that would require some design and is basically blocked on |
Thanks, was able to get to a decent place by passing the request guard errors through |
Couldn't a custom status be useful here? I quite expected |
The failure outcome already does contain a |
The failure outcome already does contain a |
Yes, it does already contain a Status. It would be good if it can accept |
A |
Is there a way of telling rocket to at least log the error in case a request guard emits |
Hello there @sclasen , it looks like you were able to solve this issue by using request local cache. However I am stuck here, a beginner in rocket and rust in general, would be really helpful if I can get a hint about the implementation. Read the docs at https://rocket.rs/v0.5/guide/state/#request-local-state and https://api.rocket.rs/v0.5/rocket/request/trait.FromRequest.html#request-local-state but stuck while catching the error in catchers. |
I have implemented a custom guard, that returns a Failure with a Status and
Json<MyError>
when the guard fails. I was expecting that the response returned by rocket would be content type application/json and that the body would be the json serialization of MyError.Instead, the Status returned from the guard does appear to be used, but the response body are all the default html error responses from rocket.
Is there a way to convince rocket to render the Error type of the Outcome as the body of the error response?
Questions
Any questions must include:
0.4.2
Reading docs, searching for examples, etc.
FromRequest api docs, Custom Guard guide.
The text was updated successfully, but these errors were encountered: