From a97d36a90f2d94ff1fcf44d606501821fe9c81ed Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Fri, 19 Jan 2024 05:44:21 -0500 Subject: [PATCH] fix: log HTTP errors (#163) --- justfile | 11 ----------- src/error.rs | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/justfile b/justfile index fcc5605..803e014 100644 --- a/justfile +++ b/justfile @@ -48,17 +48,6 @@ fmt-imports: echo '==> rustfmt not found in PATH, skipping' fi -fmt-imports: - #!/bin/bash - set -euo pipefail - - if command -v cargo-fmt >/dev/null; then - echo '==> Running rustfmt' - cargo +nightly fmt -- --config group_imports=StdExternalCrate,imports_granularity=One - else - echo '==> rustfmt not found in PATH, skipping' - fi - # Build docker image build-docker: @echo '=> Build keys-server docker image' diff --git a/src/error.rs b/src/error.rs index 71e7e8d..a0b53cd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,7 @@ use { crate::{auth, handlers::ResponseError, stores::StoreError}, axum::response::{IntoResponse, Response}, hyper::StatusCode, + tracing::{error, info, warn}, }; pub type Result = std::result::Result; @@ -44,7 +45,8 @@ pub enum Error { impl IntoResponse for Error { fn into_response(self) -> Response { - match self { + info!("Responding with error: {self:?}"); + let response = match &self { Error::Database(e) => crate::handlers::Response::new_failure( StatusCode::INTERNAL_SERVER_ERROR, ResponseError { @@ -99,6 +101,16 @@ impl IntoResponse for Error { message: "This error should not have occurred. Please file an issue at: https://github.com/walletconnect/keys-server".to_string(), } ), - }.into_response() + }.into_response(); + + if response.status().is_client_error() { + warn!("HTTP Client Error: {self:?}"); + } + + if response.status().is_server_error() { + error!("HTTP Server Error: {self:?}"); + } + + response } }