Better error handling for REST service methods

I found that it’s impossible to return meaningful errors for exceptions thrown in middleware services, when called via REST interface.

The offending code is in the


, specifically in the



There you simply throw a generic exception with a static error message (“Error on service method invoke”), while I’d like a simple way to handle custom exceptions, converting them in POJO responses.

You should implement an external bean whose scope is to handle service exceptions in a custom way (moving the default implementation there, to be overridden when needed).


Hi Paolo,
you’re right. We’ve created the issue.

:ticket: See the following issue in our bug tracker:

Hi @gorbunkov.
Is it possible to handle a custom exception in the rest api cuba implementation?
The link is broken

The fix will be in the upcoming 7.2 release. See the GitHub issue. Here is a link to the workaround that works for previous CUBA versions: How to implement service response Too Many Requests - #13 от пользователя gorbunkov - CUBA.Platform