Currently, we have an issue with exceptions thrown by REST endpoints.
More precisely, some exceptions are not logged and an HTTP 500 response with the
'No ExceptionMapper was found, but must be found' is returned to the client, without any additional log being recorded. This makes it very difficult to find the root cause of the error (for instance, https://forum.xwiki.org/t/wiki-index-empty/)
This is the case for all exceptions that:
- are checked
- does not have a corresponding
In summary that’s all checked exceptions except
WebAppExceptionand their children).
So first I propose to introduce a generic
ExceptionMapper<Exception> that would do two things:
- log the error so that we have access to the stracktrace of the exceptions (and hence be able to fix the issue more easily)
- return a response exactly similar to the one returned by
JaxRsProviders(i.e., the HTTP 500 +
'No ExceptionMapper was found, but must be found'response) to make the change transparent for the clients.
In addition, I propose to improve the best practices regarding exceptions in REST endpoints, by introducing the following rules:
- rest endpoints must never throw
Exceptionbecause it is too generic
- rest endpoints must always throw unchecked exceptions,
- other checked exceptions are not allowed unless an
ExceptionMapperis provided for them.
Existing code will be updated according to the best practices (if agreed on) on case by case basis.