So I have this exception mapper, that is currently not working:
package x.y.z
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class GeneralExceptionHandler implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception e) {
Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
ErrorMessage message = ErrorMessage.fromHttpStatus(status);
return Response.status(status).entity(message).build();
}
}
Let’s say I change it into:
package x.y.z
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class GeneralExceptionHandler implements ExceptionMapper<RuntimeException> {
@Override
public Response toResponse(RuntimeException e) {
Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
ErrorMessage message = ErrorMessage.fromHttpStatus(status);
return Response.status(status).entity(message).build();
}
}
Now it’s getting triggered, and working as expected. It’s clearly registering properly, otherwise it wouldn’t be catching exceptions no matter what type. Noticeably this stopped working when I upgraded to the Jakarta namespace. So, if an exception is a RuntimeException (and I don’t have a RuntimeException mapper defined), why isn’t it getting caught in the most general one anymore?
Nothing else is implementing a mapper for Exception (in my codebase at least). I have a few exception mappers from before (they catch custom Exceptions). The errors I’m throwing are the usual suspects, IllegalArgumentException, NullPointerException, etc.
tomEE version is 9.1.3, tomee jakartaee-api is 9.1.1.
Anything else I should look at?