Saturday, 3 March 2018

How to implement a global exception handler used by all the controllers ?


Create a Controller advice, which will be called on each controller.
  • Implement ResponseBodyAdvice
    (methods : beforeBodyWrite,
    supports)
    OR / AND
     
  • Implement RequestBodyAdvice
    (methods : beforeBodyRead, afterBodyRead, handleEmptyBody, supports)
supports method can be used to check proper content type and return boolean.

For a global exception handler, create a Controller advice and check request or manipulate the response.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.