Skip to content

Commit

Permalink
fix: log HTTP errors (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Jan 19, 2024
1 parent f7d69a4 commit a97d36a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 0 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 14 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
crate::{auth, handlers::ResponseError, stores::StoreError},
axum::response::{IntoResponse, Response},
hyper::StatusCode,
tracing::{error, info, warn},
};

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

0 comments on commit a97d36a

Please sign in to comment.