Hello! Please help me find a solution.

I have a simple RestController that accepts data in a POST request, processes it and sends the response to the client application (as a collection). How to return an http response with error codes 404, 403, etc., if, for example, an empty collection is returned after processing?

I mean, if an exception occurred in the controller's method during data processing, is it possible to return a response containing the error status? So that the error code is indicated by me? Maybe someone will tell you where to find an example or literature on this?

It seemed to me that something related to @ExceptionHandler could help, but I can’t find an explanation for it. Here is the book Manning would be very helpful if there was on this issue ...

    1 answer 1

    It seemed to me that something related to @ExceptionHandler could help, but I can’t find an explanation for it.

    It's unclear how you searched, because the very first link for the "spring exceptionhandler" produces: http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc

    • Thank you very much! For some reason I safely missed this article while searching - lester