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:
parent
640bb8263c
commit
5057de90e6
2 changed files with 6 additions and 0 deletions
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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)?)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue