1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

add errorlog feature

This commit is contained in:
Dominic 2020-02-10 21:41:44 +01:00
parent 640bb8263c
commit 5057de90e6
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 6 additions and 0 deletions

View file

@ -40,6 +40,7 @@ thiserror = "1"
[features]
default = []
auth = ["gotham_restful_derive/auth", "base64", "cookie", "jsonwebtoken"]
errorlog = []
database = ["gotham_restful_derive/database", "gotham_middleware_diesel"]
openapi = ["gotham_restful_derive/openapi", "indexmap", "log", "openapiv3"]

View file

@ -2,6 +2,7 @@ use crate::{ResponseBody, StatusCode};
#[cfg(feature = "openapi")]
use crate::{OpenapiSchema, OpenapiType};
use hyper::Body;
use log::error;
use mime::{Mime, APPLICATION_JSON, STAR_STAR};
#[cfg(feature = "openapi")]
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
@ -136,6 +137,10 @@ impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
Ok(match self {
Ok(r) => Response::json(StatusCode::OK, serde_json::to_string(&r)?),
Err(e) => {
if cfg!(feature = "errorlog")
{
error!("The handler encountered an error: {}", e);
}
let err : ResourceError = e.into();
Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)
}