in Service Discovery by
Q:
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.

Related questions

+1 vote
asked May 30, 2020 in JAVA by Robindeniel
+1 vote
asked Dec 20, 2019 in Service Discovery by sharadyadav1986
...