Skip to content

Log client error responses at warning level. - #12

Merged
gustavofreze merged 1 commit into
mainfrom
feat/client-errors-at-warning-level
Nov 10, 2026
Merged

gustavofreze merged 1 commit into
mainfrom
feat/client-errors-at-warning-level

Conversation

@gustavofreze

Copy link
Copy Markdown
Member

Please follow the contributing guidelines.

Summary

The middleware logged every response in the 4xx/5xx range at error level. A consumer therefore wrote every client mistake (a wrong password answered with 401, a validation failure answered with 422, an unknown resource answered with 404) as an error, which flooded the alerting and the error tracking that watch that level.

The level of the response entry now follows the status code:

Status code Level
5xx error (as before)
4xx warning (was error)
Any other status info (as before)
  • The request entry stays at info.
  • The notion of an error response is unchanged (Code::isErrorCode, 400 to 511), so paths set through withFailureOnlyPaths still log both 4xx and 5xx responses. A 4xx response on such a path is now written at warning, the same level any other path gets.
  • The change lives in Internal/LogResponse. The public API is untouched.
  • README overview updated. The LogMiddlewareBuilder and LogMiddleware docblocks speak of responses that are an error, never of a level, so they still hold and are unchanged.

Release

Recommended release: 1.6.0 (minor). The public API does not change, but the documented level of 4xx responses does, and a consumer whose alerting relied on 4xx entries at error stops receiving them. That is a visible change in behavior, not a bug fix, so it is not a patch.

Related issue

None. The need came from consumers whose error alerting was flooded by client mistakes.

Checklist

  • Tests added or updated. 14 new cases, 84 tests in total: a status-to-level data set at the boundaries 399 (info), 400 and 499 (warning), 500 (error), plus 200, 302, 401, 404, 422, 503 and 511. The 422 test now expects warning and no error. Failure-only paths are covered at 399 (nothing logged) and at 400, 404, 422, 499 (warning) and 500, 503 (error), and an unlisted path next to configured filters logs 422 at warning.
  • Documentation updated when applicable. README overview.
  • make review passes.
  • make tests passes: 84 tests, 148 assertions, 117 mutants, all killed, MSI 100%.

A 4xx response is a client mistake, such as a wrong password, a failed
validation or an unknown resource, not a failure of the service. Logging
it at error level flooded the alerts that watch that level. Responses in
the 5xx range stay at error, and failure-only paths still log both 4xx
and 5xx responses.
@gustavofreze
gustavofreze merged commit c27177c into main Nov 10, 2026
5 checks passed
@gustavofreze
gustavofreze deleted the feat/client-errors-at-warning-level branch November 10, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant