Log error details instead of sending them in HTTP responses
This commit is contained in:
parent
1812bedfd2
commit
1484ecabe9
2 changed files with 18 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
|
dev::Service,
|
||||||
middleware::{Compress, Logger, NormalizePath},
|
middleware::{Compress, Logger, NormalizePath},
|
||||||
rt::System,
|
rt::System,
|
||||||
web::{self, ServiceConfig},
|
web::{self, ServiceConfig},
|
||||||
|
@ -48,6 +49,19 @@ pub fn run(app: App) -> Result<(), std::io::Error> {
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
ActixApp::new()
|
ActixApp::new()
|
||||||
.wrap(Logger::default())
|
.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())
|
.wrap(Compress::default())
|
||||||
.configure(make_config(app.clone()))
|
.configure(make_config(app.clone()))
|
||||||
})
|
})
|
||||||
|
|
|
@ -93,6 +93,10 @@ impl ResponseError for APIError {
|
||||||
APIError::VFSPathNotFound => StatusCode::NOT_FOUND,
|
APIError::VFSPathNotFound => StatusCode::NOT_FOUND,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn error_response(&self) -> HttpResponse<BoxBody> {
|
||||||
|
HttpResponse::new(self.status_code())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue