I'm currenlty developping a web API with Rocket that use the following struct for error responses :
#[derive(Serialize, Deserialize)]
pub struct ErrorResponse {
code: u16,
reason: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
}
Actually, serializing this struct produce json similar to this :
{
"code": 400,
"reason": "Bad Request"
}
I'm looking to serialize it this way:
{
"error": {
"code": 400,
"reason": "Bad Request"
}
}
What is the easiest way to do that without using two different sructs ?
Thank you in advance for your help!