Skip to content

Commit

Permalink
Log message when ErrorResponse is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
BBaoVanC committed Jan 19, 2023
1 parent 7cc7197 commit 24424bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Log a message when ErrorResponse is return from a view

### Fixed

- Change upload page text from "Click or drop files here" to "Click to select files" because you cannot actually drop files currently.
Expand Down
11 changes: 11 additions & 0 deletions bobashare-web/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use askama_axum::IntoResponse;
use axum::{routing::get, Router};
use chrono::Duration;
use hyper::StatusCode;
use tracing::{event, Level};
use url::Url;

use crate::AppState;
Expand Down Expand Up @@ -66,6 +67,16 @@ impl From<ErrorTemplate> for ErrorResponse {
}
impl IntoResponse for ErrorResponse {
fn into_response(self) -> askama_axum::Response {
let code = self.0.code;
let error_msg = &self.0.message;
if code.is_server_error() {
event!(Level::ERROR, status = code.as_u16(), error = error_msg);
} else if code.is_client_error() {
event!(Level::WARN, status = code.as_u16(), error = error_msg);
} else {
event!(Level::INFO, status = code.as_u16(), error = error_msg);
}

(self.0.code, self.0).into_response()
}
}
Expand Down

0 comments on commit 24424bd

Please sign in to comment.