Skip to content

Add opt-out for default RestClient status handler#36251

Open
seungy0 wants to merge 1 commit intospring-projects:mainfrom
seungy0:disable-default-status-handler
Open

Add opt-out for default RestClient status handler#36251
seungy0 wants to merge 1 commit intospring-projects:mainfrom
seungy0:disable-default-status-handler

Conversation

@seungy0
Copy link

@seungy0 seungy0 commented Feb 4, 2026

Summary

Introduce an explicit opt-out for the built-in default RestClient status handler (4xx/5xx → exception).
This allows users to fully control status handling without the “always-match” workaround.

Motivation

  • Default StatusHandler is added implicitly, which is hard to discover.
  • NoOpResponseErrorHandler does not disable the built-in handler.
  • Treating some 4xx/5xx as normal outcomes is currently cumbersome.

Related issue: #36248

Changes

  • Add RestClient.Builder#disableDefaultStatusHandler() (default behavior unchanged).
  • Skip built-in handler registration when disabled.
  • Update Javadoc to document the opt-out.
  • Tests verifying default behavior vs opt-out.

Tests

  • DefaultRestClientTests.defaultStatusHandlerThrowsOnErrorStatus
  • DefaultRestClientTests.disableDefaultStatusHandlerAllowsErrorBody
  • RestClientBuilderTests.disableDefaultStatusHandler

Notes

Backward compatible. Opt-in only.

Signed-off-by: Seunggyu Lee <dltmdrb98@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 4, 2026
@LavaC3
Copy link

LavaC3 commented Feb 4, 2026

@seungy0
Thanks for your feedback and fixing this issue perfectly!

🙏 I realize my previous implementation had an oversight (didn't consider the built-in StatusHandler logic in DefaultResponseSpec), and your solution with a dedicated disable flag passed to DefaultResponseSpec is definitely the right and complete approach.

It's a great learning for me to dive into the RestClient source code and Spring contribution process through this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants