Skip to content

Conversation

@ComputerDaddyGuy
Copy link

@ComputerDaddyGuy ComputerDaddyGuy commented Dec 13, 2025

Current behavior

  • In order to allow loadbalancer lifecycle processors to handle failed requests, the lb filter catches any Exception thrown from subsequent filters. After processing, the exception is rethrown but wrapped into a RuntimeException
  • This wrap is (I suppose) originally due to usage of lambda, which does not allow to throw checked exceptions.
return (request, next) -> {
	// ...
	try {
		// Call subsequent filters
	}
	catch (Exception e) {
		supportedLifecycleProcessors.forEach(...); // Handle CompletionContext.Status.FAILED
		throw new RuntimeException(e); // <-- wrap and rethrow
	}
};

Issue

  • Wrapping into a RuntimeException prevents error handlers to catch the original exception
var builder = RouterFunctions.route();

// Not working because of RuntimeException wrap
builder = builder.onError(MyCustomException.class::isInstance, (ex, request) -> ...);

// Custom exception is catched here
builder = builder.onError(_ -> true, (ex, request) -> ...);

Proposed solution in this PR

  • The lb filter has been adapted to use an anonymous class instead of a lambda
  • The original exception is rethrown as is, without any change or wrap
  • A test has been added to ensure the lb filter does not wrap the original exception

Signed-off-by: Samuel SCHNEGG <samuel.schnegg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants