admin管理员组

文章数量:1289565

In my QuarkusApplication I need a dedicated errorhandling for all servererros. Meaning every Exception occuring inside my Controller-Logic needs to be handled by my ExceptionMapper, Quarkus' error handling of client-failures should not be affected.

First idea:

class MyDefautlExceptionMapper implements ExceptionMapper<Exception> {
// ...
}

This does as expected for my servererrors, but gets also triggered i.e. when the user calls a wrong url and should get a 404, or if a wrong method is used and should be answered by 405.

One solution would be to add a try catch to every controller-method and map everything to some dedicated Exception and handle that one

@GET
@Path("/foo")
public Baa handleRequest() {
try {
  // do what to do
} catch (Exception e) {
  throw MySpecialException();
}

and

class MySpecialExceptionMapper implements ExceptionMapper<MySpecialException> {
// ...
}

But that's ugly and error-prone when being added to dozens of methods. What's the right approach to my problem?

本文标签: restDefault ExceptionMapper for QuarkusStack Overflow