Search code examples
javarestspring-booterror-handlingcustom-exceptions

How to handle Exceptions in Rest API whit Spring boot


I need to handle the exceptions in My rest API. I have a layered architecture, composed by Entities, DAOs, Services and controllers. In my services I have the model Exceptions, and I need to know the best way to translate these exceptions to send responses in HTTP. I read about Exception handler and Controller advice but I'm not sure how is the best form to do this. Anyone can iluminate me? Thanks


Solution

  • One way is by the use of spring ExceptionHandler (there are several variants possible depending on spring version).

    Some good documentation here