Skip to content

Commit

Permalink
Auto merge of #3908 - Turbo87:at-error, r=pietroalbini
Browse files Browse the repository at this point in the history
LogRequest: Use `at=error` for all 5xx status code responses

We are currently only using `at=error` for cases where the route handler did not explicitly return a 5xx status code, but we should probably use it for all cases where 5xx is returned. This PR changes the code to achieve that.
  • Loading branch information
bors committed Sep 11, 2021
2 parents 36a59d0 + c3535b4 commit 5d2e10f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/middleware/log_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ impl Display for RequestLine<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut line = LogLine::new(f);

let (at, status) = match self.res {
Ok(resp) => ("info", resp.status()),
Err(_) => ("error", StatusCode::INTERNAL_SERVER_ERROR),
let status = self.res.as_ref().map(|res| res.status());
let status = status.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);

let at = if status.is_server_error() {
"error"
} else {
"info"
};

line.add_field("at", at)?;
Expand Down

0 comments on commit 5d2e10f

Please sign in to comment.