Better error handling for REST service methods

Hi
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

ServicesControllerManager

, specifically in the

_invokeServiceMethod

implementation.

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).

Thanks,
Paolo

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

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

https://youtrack.cuba-platform.com/issue/PL-9864

Hi @gorbunkov.
Is it possible to handle a custom exception in the rest api cuba implementation?
The link https://youtrack.cuba-platform.com/issue/PL-9864 is broken

Hi,
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