I have an application developed with a microservices architecture. Each microservice is a spring-boot application that communicates with others via FeignClient interface.
Let A, a microservice (RestAPI) that calls microservice B. In normal conditions, B replies with an Object X, that is the JSON-response that A serves to client.
But, if B throws an exception, I obtain a chinese-box exception to the client like this:
{
"timestamp": 1511965051071,
"status": 500,
"error": "Internal Server Error",
"exception": "Exception",
"message": { "\"timestamp\":1511965051052,\"status\":422,\"error\":\"Unprocessable Entity\",\"exception\":\"java.lang.MyException\",\"message\":\"Error message from B\",\"path\":\"PATH-OF-B-SERVICE\"}",
"path": "PATH-OF-A-SERVICE"
}
In other words, MyException (status 422) is "embedded" in A Exception (status 500).
I would like to reply the client with the inner JSON, that is:
{
"timestamp": 1511965051052,
"status": 422,
"error": "Unprocessable Entity",
"exception": "java.lang.MyException",
"message": "ErrormessagefromB",
"path": "PATH-OF-B-SERVICE"
}
How can I do that?