Skip to content

fix: only log 4xx errors when debug is enabled in DebuggableExceptionMapper#691

Open
VinayakGote (Vinu2111) wants to merge 1 commit into
confluentinc:masterfrom
Vinu2111:fix/debuggable-exception-mapper-log-level
Open

fix: only log 4xx errors when debug is enabled in DebuggableExceptionMapper#691
VinayakGote (Vinu2111) wants to merge 1 commit into
confluentinc:masterfrom
Vinu2111:fix/debuggable-exception-mapper-log-level

Conversation

@Vinu2111
Copy link
Copy Markdown

Problem

When debug=false, 4xx errors (such as RestNotFoundException) were still
being logged via log.debug(...) unconditionally in DebuggableExceptionMapper.
The comment in the code said "Only log other errors, including user-errors 4xx,
if debugging enabled" — but the condition was never actually checked for logging.

Fixes the behaviour described in #221.

Change

In createResponse(), the else branch that logs 4xx errors has been changed
to an else if that checks restConfig.getBoolean(RestConfig.DEBUG_CONFIG)
before logging. 5xx errors are unaffected — they always log at ERROR level.

Before:

} else {
  log.debug("Request Failed with exception ", exc);
}

After:

} else if (restConfig != null && restConfig.getBoolean(RestConfig.DEBUG_CONFIG)) {
  log.debug("Request Failed with exception ", exc);
}

Tests

Added DebuggableExceptionMapperTest covering three cases:

  • 4xx with debug=false → no stack trace in response message
  • 4xx with debug=true → stack trace included in response message
  • 5xx with debug=false → always logs, no stack trace in message

@Vinu2111 VinayakGote (Vinu2111) requested review from a team as code owners May 1, 2026 04: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