From 5057de90e660b393f6c1731ecac00fc36a8df48f Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 10 Feb 2020 21:41:44 +0100 Subject: [PATCH] add errorlog feature --- gotham_restful/Cargo.toml | 1 + gotham_restful/src/result.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/gotham_restful/Cargo.toml b/gotham_restful/Cargo.toml index 328b9dc..d7b4936 100644 --- a/gotham_restful/Cargo.toml +++ b/gotham_restful/Cargo.toml @@ -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"] diff --git a/gotham_restful/src/result.rs b/gotham_restful/src/result.rs index f6057ae..76d7ede 100644 --- a/gotham_restful/src/result.rs +++ b/gotham_restful/src/result.rs @@ -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 ResourceResult for Result 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)?) }