Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log HTTP errors #163

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}