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
ExceptionMapper
.
In summary that’s all checked exceptions exceptXWikiRestException
,WebAppException
and 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
Exception
because it is too generic - rest endpoints must always throw unchecked exceptions,
XWikiRestException
, orWebAppException
- other checked exceptions are not allowed unless an
ExceptionMapper
is provided for them.
Existing code will be updated according to the best practices (if agreed on) on case by case basis.
WDYT?