mirror of
https://github.com/agersant/polaris
synced 2024-11-10 02:04:13 +00:00
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::{
|
||||
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()))
|
||||
})
|
||||
|
|
|
@ -93,6 +93,10 @@ impl ResponseError for APIError {
|
|||
APIError::VFSPathNotFound => StatusCode::NOT_FOUND,
|
||||
}
|
||||
}
|
||||
|
||||
fn error_response(&self) -> HttpResponse<BoxBody> {
|
||||
HttpResponse::new(self.status_code())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in a new issue