You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I have a route which basically takes in a json request and tries to bind it to a struct. I have implemented the binding using the Json data guard, however I'm having issues retrieving the error message passed in by the guard when it fails.
#[post("/create", format="json", data="<user>")]pubasyncfncreate_user(user:Json<CreateUser>) -> Value{let user = User::new(user.into_inner());json!({"status":"ok","user": user
})}
this is my route and when it fails, this is the error thrown,
Data guard `Json < CreateUser >` failed:Parse("{}",Error("missing field `name`", line:1, column:2)).
now I've implemented a catcher for the 422 status errors,
is there a way to pass the error message in the catcher, so instead of plain "unprocessable entity" it should say "unprocessable entity: missing field `name`"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So I have a route which basically takes in a json request and tries to bind it to a struct. I have implemented the binding using the Json data guard, however I'm having issues retrieving the error message passed in by the guard when it fails.
this is my route and when it fails, this is the error thrown,
now I've implemented a catcher for the 422 status errors,
is there a way to pass the error message in the catcher, so instead of plain "unprocessable entity" it should say "unprocessable entity: missing field `name`"
Beta Was this translation helpful? Give feedback.
All reactions