From d9c22579b06d38e7dcad84ffbb632eb34b03cba0 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 19 Sep 2020 19:40:39 +0200 Subject: [PATCH] only log errors on 500 responses (fixes #30) --- src/lib.rs | 3 +++ src/result/mod.rs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 92bf691..a45dc83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -338,11 +338,14 @@ openapi = ["gotham-restful/openapi"] into your libraries `Cargo.toml` and use the following for all types used with handlers: ``` +# #[cfg(feature = "openapi")] +# mod openapi_feature_enabled { # use gotham_restful::OpenapiType; # use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] #[cfg_attr(feature = "openapi", derive(OpenapiType))] struct Foo; +# } ``` # Examples diff --git a/src/result/mod.rs b/src/result/mod.rs index 100ba55..2c79d37 100644 --- a/src/result/mod.rs +++ b/src/result/mod.rs @@ -104,8 +104,17 @@ where E: Display + IntoResponseError { into_response_helper(|| { - errorlog(&e); - e.into_response_error() + let msg = e.to_string(); + let res = e.into_response_error(); + match &res { + Ok(res) if res.status.is_server_error() => errorlog(msg), + Err(err) => { + errorlog(msg); + errorlog(&err); + }, + _ => {} + }; + res }) }