1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

allow Result<NoContent> responses

This commit is contained in:
Dominic 2019-10-05 16:06:08 +02:00
parent a28ccb98f1
commit 75c399d97a
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -123,3 +123,29 @@ impl ResourceResult for NoContent
StatusCode::NO_CONTENT
}
}
impl<E : Error> ResourceResult for Result<NoContent, E>
{
fn to_json(&self) -> Result<(StatusCode, String), SerdeJsonError>
{
Ok(match self {
Ok(_) => (StatusCode::NO_CONTENT, "".to_string()),
Err(e) => {
let err : ResourceError = e.into();
(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)
}
})
}
#[cfg(feature = "openapi")]
fn to_schema() -> OpenapiSchema
{
<()>::to_schema()
}
#[cfg(feature = "openapi")]
fn default_status() -> StatusCode
{
StatusCode::NO_CONTENT
}
}