In rocket default the error catcher will return html response, I want to modify this and return json response instead:
#[catch(422)]
pub fn unprocessable_entity(req: &Request) -> Json<String> {
let message = "".to_string();
Json(message)
}
here is the struct to deserialized using the rocket serde:
#[derive(Deserialize, Debug)]
pub struct Product {
pub name: Option<String>,
}
when I send incorrect JSON request type ex (name as number):
{
"name": 1
}
I could get data guard deserialization error on the running terminal rocket logs like this:
…Error(“invalid type: integer
2
, expected a string”, line: 5,
column: 19)).
How can i return the data guard error from the logs to the catcher and return it as JSON? from the rocket doc i read the catcher method only accept 0 or 1 argument which is theRequest
type