Exception Handler Interceptor

304 views
Skip to first unread message

Jose Santa Elena Nunes Neto

unread,
Aug 26, 2023, 4:21:53 PM8/26/23
to Quarkus Development mailing list
0

My interceptor is not catching the exceptions thrown by intercepted method, the interceptor is being invoked, but when the method throws an Exceptions seems that Quarkus is handling it, and my catch block is never executed.

Is there a way to handle exceptions instead of using JAX-RS ExceptionMapper?

Thanks


@HandleError(domain = Domain.NONE)
@Interceptor
@Priority(10)
public class HandleErrorInterceptor {
@Inject
LoggingHelper log;
@Inject
SystemParameters params;
@Inject
ErrorHelper err;

@AroundInvoke
public Object catchErrors(InvocationContext context) throws Exception {
if (!Result.class.isAssignableFrom(context.getMethod().getReturnType()))
err.raise(903L, context.getMethod());

HandleError handleError = context.getMethod().getAnnotation(HandleError.class);

if (handleError == null) {
return context.proceed();
}

Object result = null;

try {
result = context.proceed();
} catch (Exception ex) {
SystemMessage sysMsg;

if (ex instanceof ServiceRuntimeException)
sysMsg = ((ServiceRuntimeException) ex).getSystemMessage();
else {
sysMsg = params.getSystemMessage(999L);

log.error(handleError.domain(), ex, ex.getMessage());

result = context.getMethod().getReturnType().getConstructor().newInstance();
((Result) result).setStatusCode(sysMsg.getCode());
((Result) result).setStatusMessage(ex.getMessage());
}
}

return result;
}
}

Georgios Andrianakis

unread,
Aug 28, 2023, 2:16:37 AM8/28/23
to jsant...@gmail.com, Quarkus Development mailing list
Hi,

Please use Github Discussions or our Zulip Chat for such kinds of questions.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/4d18a549-b115-4481-ac48-1a8bbf0ee80an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages