in Service Discovery by
How will you deploy Exception Handling in Microservices?

1 Answer

0 votes
by

If an exception occurs while processing an HTTP request, you need to catch the exception in your controller or service and return an appropriate ResponseEntity manually.  Here are some thumb rules for exception handling.

Add @ResponseStatus for exceptions that you write.

For all other exceptions, implement an @ExceptionHandler method on a @ControllerAdvice class or use an instance of SimpleMappingExceptionResolver. 

For Controller specific exceptions, add @ExceptionHandler methods to your controller. 

Point to be noted is that @ExceptionHandler methods on the controller are always selected before those on any @ControllerAdvice instance. It is undefined in what order ControllerAdvices are processed.

...