January 2018
Intermediate to advanced
414 pages
10h 29m
English
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 annotations.
First, lets create a new Kotlin class and name it ErrorHandler:
package com.microservices.chapter3import com.fasterxml.jackson.core.JsonParseExceptionimport org.springframework.http.HttpStatus ...
Read now
Unlock full access