From 1484ecabe93f0ef9edf1d6e6c08663dd45239724 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Mon, 21 Nov 2022 18:37:55 -0800 Subject: [PATCH] Log error details instead of sending them in HTTP responses --- src/service/actix.rs | 14 ++++++++++++++ src/service/actix/api.rs | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/service/actix.rs b/src/service/actix.rs index de8ca18..0fce678 100644 --- a/src/service/actix.rs +++ b/src/service/actix.rs @@ -1,4 +1,5 @@ use actix_web::{ + dev::Service, middleware::{Compress, Logger, NormalizePath}, rt::System, web::{self, ServiceConfig}, @@ -48,6 +49,19 @@ pub fn run(app: App) -> Result<(), std::io::Error> { HttpServer::new(move || { ActixApp::new() .wrap(Logger::default()) + .wrap_fn(|req, srv| { + // For some reason, actix logs error as DEBUG level. + // This logs them as ERROR level + // See https://github.com/actix/actix-web/issues/2637 + let response_future = srv.call(req); + async { + let response = response_future.await?; + if let Some(error) = response.response().error() { + error!("{}", error); + } + Ok(response) + } + }) .wrap(Compress::default()) .configure(make_config(app.clone())) }) diff --git a/src/service/actix/api.rs b/src/service/actix/api.rs index 805c0ab..4339412 100644 --- a/src/service/actix/api.rs +++ b/src/service/actix/api.rs @@ -93,6 +93,10 @@ impl ResponseError for APIError { APIError::VFSPathNotFound => StatusCode::NOT_FOUND, } } + + fn error_response(&self) -> HttpResponse { + HttpResponse::new(self.status_code()) + } } #[derive(Debug)]