mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 13:02:28 +00:00
properly enable/disable errorlog
This commit is contained in:
parent
311a7f082b
commit
5d730df90d
1 changed files with 11 additions and 4 deletions
|
@ -2,6 +2,7 @@ use crate::{ResponseBody, StatusCode};
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
use crate::{OpenapiSchema, OpenapiType};
|
use crate::{OpenapiSchema, OpenapiType};
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
|
#[cfg(feature = "errorlog")]
|
||||||
use log::error;
|
use log::error;
|
||||||
use mime::{Mime, APPLICATION_JSON, STAR_STAR};
|
use mime::{Mime, APPLICATION_JSON, STAR_STAR};
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
|
@ -130,6 +131,15 @@ impl<T : ToString> From<T> for ResourceError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "errorlog")]
|
||||||
|
fn errorlog<E : Display>(e : E)
|
||||||
|
{
|
||||||
|
error!("The handler encountered an error: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "errorlog"))]
|
||||||
|
fn errorlog<E>(_e : E) {}
|
||||||
|
|
||||||
impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
|
impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
|
||||||
{
|
{
|
||||||
fn into_response(self) -> Result<Response, SerdeJsonError>
|
fn into_response(self) -> Result<Response, SerdeJsonError>
|
||||||
|
@ -137,10 +147,7 @@ impl<R : ResponseBody, E : Error> ResourceResult for Result<R, E>
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Ok(r) => Response::json(StatusCode::OK, serde_json::to_string(&r)?),
|
Ok(r) => Response::json(StatusCode::OK, serde_json::to_string(&r)?),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if cfg!(feature = "errorlog")
|
errorlog(&e);
|
||||||
{
|
|
||||||
error!("The handler encountered an error: {}", e);
|
|
||||||
}
|
|
||||||
let err : ResourceError = e.into();
|
let err : ResourceError = e.into();
|
||||||
Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)
|
Response::json(StatusCode::INTERNAL_SERVER_ERROR, serde_json::to_string(&err)?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue