-
-
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 to return error as a Json from FromParam #2714
Comments
The easiest thing to do is this: type ApiResult<T> = Result<T, Custom<Json<ErrorApiOutput>>>;
#[get("/customers/<customer_id>")]
pub fn get_customer(customer_id: ApiResult<CustomerId>) -> ApiResult<String> {
let id = customer_id?;
Ok(id.to_string())
} |
working! thank u very much @SergioBenitez do u think that we should update documentation? for me connection between fully working code for ref:
|
This is already mentioned here: https://rocket.rs/v0.5/guide/requests/#fallible-guards. But I'll keep this in mind for future iteration of the docs. P.S: You created a |
What kind of documentation problem are you reporting?
Technical Problem
Where is the issue found?
https://api.rocket.rs/v0.5/rocket/request/trait.FromParam.html
What's wrong?
what I would like to have: returning error in json format from
FromParam
expectations
something like this, but using
FromParam
:so: to parse correctly
CustomerId
or to returnUnprocessableEntity
with json body:code:
problem
I specified
FromParam
to parseString
intoCustomerId(Uuid)
; when it is not correct I want to show appropriate error as a Jsonas I checked with curl:
curl http://localhost:8000/api/customers/550e8400-e29b-41d4-a716-44665544000
html is returned, and it does not contain appropriate error message
what is more - documentation does not specify how to return
Json
for that caseSystem Checks
master
on GitHub.The text was updated successfully, but these errors were encountered: