-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Hands-On Microservices with Kotlin
By :

Any software needs to handle errors, either triggered by the business rules that are defined or just to handle extraordinary circumstances that may appear. In RESTful APIs, we use status codes to tell our consumers when an error has occurred, but within our code, we need to handle those scenarios and ensure that they are handled gracefully. During this section, we will review some of the techniques that we could use to handle these situations.
In our last example, we got an exception when our JSON was not formatted correctly. That exception was JsonParseException
, and was not handled in any part of our code so Spring was automatically handling it for us and returning an error message.
But we may want to handle the exception yourself so we could customize the error, and the body of the message is returned. For doing so, Spring provides a mechanism to handle any exception that was not caught in our application code using the ControllerAdvice
and ExceptionHandler...