Skip to content

ResponseEntityExceptionHandler with @ControllerAdvice is Ignored when using spring-modulith-observability #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bekaChichua opened this issue Nov 19, 2024 · 1 comment
Assignees
Labels
in: observability Observability support meta: waiting for feedback Waiting for feedback of the original reporter type: bug Something isn't working

Comments

@bekaChichua
Copy link

Issue: ResponseEntityExceptionHandler with @ControllerAdvice is Ignored When Using spring-modulith-observability

Description

When spring-modulith-observability is included in the project dependencies, a custom class that extends ResponseEntityExceptionHandler and is annotated with @ControllerAdvice fails to catch exceptions as expected.

It appears that the exception handling flow is being disrupted, and the @ControllerAdvice is completely ignored.

From initial investigation, the issue seems to be related to the ModuleEntryInterceptor class. The interceptor wraps the controller method invocation (MethodInvocation.proceed()), and it appears to interfere with Spring MVC’s exception handling mechanism.

Steps to Reproduce

1.	Include spring-modulith-observability in your dependencies.
2.	Create a class that extends ResponseEntityExceptionHandler and annotate it with @ControllerAdvice.
3.	Throw an exception (e.g., RuntimeException) from a controller method.
4.	Observe that the exception is not handled by the custom exception handler.

Expected Behavior

•	The @ControllerAdvice class that extends ResponseEntityExceptionHandler should catch exceptions and provide the appropriate response.

Actual Behavior

•	The @ControllerAdvice is ignored, and exceptions are not caught by the custom exception handler.

Suspected Cause

•	The ModuleEntryInterceptor from spring-modulith-observability appears to intercept the method invocation and disrupt exception propagation.
•	It does not properly propagate the exceptions back to Spring MVC’s error handling flow, potentially causing the issue.

Environment

•	Spring Boot Version: 3.3.x
•	Spring Modulith Observability Version: 1.2.4
•	Java Version: 21
@odrotbohm
Copy link
Member

This seems to duplicate GH-933 as ResponseEntityExceptionHandler implements an interface. Thus, a JDK proxy is created and the annotations on the actual class are not visible anymore. As a workaround, would you mind not making the class public? If a type is not part of a module's API it is not decorated anyway, and I'd argue that a REEH doesn't need to be a type exposed by a module.

For future reference, it would be appreciated if you provided a minimal reproducer instead of instructions on how to create a sample.

@odrotbohm odrotbohm self-assigned this Nov 19, 2024
@odrotbohm odrotbohm added in: observability Observability support type: bug Something isn't working meta: waiting for feedback Waiting for feedback of the original reporter labels Nov 19, 2024
@odrotbohm odrotbohm changed the title ResponseEntityExceptionHandler with @ControllerAdvice is Ignored When Using spring-modulith-observability ResponseEntityExceptionHandler with @ControllerAdvice is Ignored when using spring-modulith-observability Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: observability Observability support meta: waiting for feedback Waiting for feedback of the original reporter type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants