Prevent loadbalancer filter to wrap exception into RuntimeException#4020
Merged
ryanjbaxter merged 3 commits intospring-cloud:mainfrom Apr 15, 2026
Merged
Conversation
Signed-off-by: Samuel SCHNEGG <samuel.schnegg@gmail.com>
Contributor
Author
|
Any chance that maybe @ryanjbaxter or @spencergibb (or any one else) review this PR? Is it missing something, or maybe should I abandon it? |
Member
|
Please be patient |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Spring Cloud Gateway Server MVC load balancer (lb) filter so that exceptions from downstream filters are rethrown without being wrapped in a RuntimeException, enabling router error handlers to match on the original exception type.
Changes:
- Refactors the
lb(...)filter implementation to rethrow the original exception instead of wrapping it. - Adds an integration test route and assertion verifying the original exception type/message are preserved.
- Introduces a test-only filter chain that captures exception details into response headers for verification.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java | Stops wrapping downstream exceptions in RuntimeException and rethrows the original exception after lifecycle completion processing. |
| spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java | Adds a new integration test and router function to verify exceptions are not wrapped by the load balancer filter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Samuel SCHNEGG <samuel.schnegg@gmail.com>
Signed-off-by: Samuel SCHNEGG <samuel.schnegg@gmail.com>
Contributor
|
I also cherrypicked this into the 4.3.x branch 0420992 |
Contributor
Author
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current behavior
lbfilter catches anyExceptionthrown from subsequent filters. After processing, the exception is rethrown but wrapped into aRuntimeExceptionIssue
RuntimeExceptionprevents error handlers to catch the original exceptionProposed solution in this PR
lbfilter has been adapted to use an anonymous class instead of a lambdalbfilter does not wrap the original exception