From 09bfddb9630ecb327548531a8cba6d3bc12bc1cc Mon Sep 17 00:00:00 2001 From: Kent Tristan Yves Sarmiento Date: Tue, 26 Dec 2023 07:21:49 +0000 Subject: [PATCH] enhancement --- link-for-later/src/controller/error.rs | 51 +++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/link-for-later/src/controller/error.rs b/link-for-later/src/controller/error.rs index c911125..b7c8a0f 100644 --- a/link-for-later/src/controller/error.rs +++ b/link-for-later/src/controller/error.rs @@ -10,50 +10,51 @@ use crate::types::AppError; #[allow(clippy::cognitive_complexity)] impl IntoResponse for AppError { fn into_response(self) -> Response { + let error_message = self.to_string(); let (status, error_message) = match self { Self::ServerError(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, error_message) } Self::DatabaseError(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, error_message) } Self::LinkNotFound(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::NOT_FOUND, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::NOT_FOUND, error_message) } Self::UserAlreadyExists(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::BAD_REQUEST, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::BAD_REQUEST, error_message) } Self::UserNotFound(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::BAD_REQUEST, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::BAD_REQUEST, error_message) } Self::IncorrectPassword(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::UNAUTHORIZED, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::UNAUTHORIZED, error_message) } Self::AuthorizationError(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::UNAUTHORIZED, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::UNAUTHORIZED, error_message) } Self::ValidationError(ref e) => { - tracing::info!("{}", self.to_string()); - tracing::debug!("{}: {}", self.to_string(), e.to_string()); - (StatusCode::BAD_REQUEST, self.to_string()) + tracing::info!("{}", error_message); + tracing::debug!("{}: {}", error_message, e.to_string()); + (StatusCode::BAD_REQUEST, error_message) } #[cfg(test)] - Self::TestError => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()), + Self::TestError => (StatusCode::INTERNAL_SERVER_ERROR, error_message), }; let body = Json(json!({