Kev
01/16/2024, 11:48 AM@ControllerAdvice
class ErrorExceptionHandler {
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
@ExceptionHandler(ApplicationException::class)
suspend fun onApplicationException(exception: ApplicationException, request: WebRequest): ResponseEntity<String> {
logger.warn("We are in the exception handler!")
return ResponseEntity.badRequest().body("bad!")
}
}
DEBUG [TestApp,173201bb4ca1afc45467a02904f0bc24,85bbccda6da914f1] 35257 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler com.testapp.configurations.http.ErrorExceptionHandler#onApplicationException(ApplicationException, WebRequest, Continuation)
WARN [TestApp,173201bb4ca1afc45467a02904f0bc24,85bbccda6da914f1] 35257 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Failure in @ExceptionHandler com.testapp.configurations.http.ErrorExceptionHandler#onApplicationException(ApplicationException, WebRequest, Continuation)
java.lang.IllegalStateException: Could not resolve parameter [2] in public java.lang.Object com.testapp.configurations.http.ErrorExceptionHandler.onApplicationException(com.testapp.ApplicationException,org.springframework.web.context.request.WebRequest,kotlin.coroutines.Continuation<? super org.springframework.http.ResponseEntity<java.lang.String>>): No suitable resolver
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:223)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:179)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:432)
at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:74)
at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:175)
at org.springframework.web.servlet.handler.HandlerExceptionResolverComposite.resolveException(HandlerExceptionResolverComposite.java:80)
...
renatomrcosta
01/16/2024, 12:09 PMsuspend
modifier in your handler? It adds a Continuation
to the generated method, and may be causing your issueKev
01/16/2024, 12:19 PMrenatomrcosta
01/16/2024, 12:31 PMsuspend
modifier is indeed fine. The signature of onApplicationException
for webflux does not have the request as a parameter. You should use it as:
suspend fun onApplicationException(exception: ApplicationException): ResponseEntity<String> {
logger.warn("We are in the exception handler!")
return ResponseEntity.badRequest().body("bad!")
}
Kev
01/16/2024, 1:05 PMkubele
01/17/2024, 9:20 PMexchange: ServerWebExchange
Kev
01/18/2024, 2:12 AMhantsy
03/29/2024, 6:08 AM