-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Use case
We need to treat some non-200 responses as valid business outcomes.
Specifically, the API returns a JSON error payload with business error codes.
For a known subset of error codes, the client should NOT throw and should return the response to the caller.
We are using RestClient via RestClientAdapter (HttpServiceProxyFactory).
What I tried
I registered a custom ResponseErrorHandler via RestClient.Builder.defaultStatusHandler(...).
The handler’s hasError(...) returns false for known business error codes so they can be handled as normal responses.
However, RestClient still throws for 4xx/5xx because a default StatusHandler is always added and runs after my handler when hasError returns false.
To fully bypass it, I had to add a handler that matches ALL status codes and conditionally runs the error handling inside it. That workaround is brittle and non-obvious.
Problem
- The default StatusHandler is added implicitly (DefaultResponseSpec constructor).
- It is hard to discover why 4xx/5xx still throw even after registering a custom ResponseErrorHandler.
- There is no official way to disable the default handler (NoOpResponseErrorHandler does not remove it).
Enhancement request
Provide an opt-out for the default StatusHandler, e.g.
RestClient.Builder.disableDefaultStatusHandler()orRestClient.Builder.defaultStatusHandlerEnabled(boolean)
Default behavior should remain unchanged.
Related
Issue: #33276
Thank you.