0

In my app Service A communicates with service B. in Service B I do some db queries so there can come up a NOT_FOUND status.

Code:

Service A

try{
RestTemplate.exchange()...
}catch(HttpStatusCodeException e){

return new ResonseEntity<String>(// Here custom message of service B extracted from e //,e.getStatusCode)
}

Service B:

return new ResponseEntity<String> ("My Error Message", HttpStatus.NOT_FOUND)

So basically I want to use "My Error Message" in the exceptionhandling in Service A. Is there a way to pass it to the exception?

1 Answer 1

1

HttpStatusCodeException inherits a method called getResponseBodyAsString simply use e.getResponseBodyAsString() and you will get the custom message sent by Service B.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Exactly what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.