Reputation: 533
I have a post method which can produce two types of response. The first one is with 200-OK status:
{"payment_uuid": "8f7f62e7-8ede-42d1-901c-68ae2651bc82"}
The second one is for an error:
["The user already has a subscription"]
I use FeignClient, my current type of a response is ResponseEntity<T>
.
How can I check, is the body has a JSON type with a payment_uuid
field or with a response description? Do I need to change response type of my method?
Upvotes: 0
Views: 826
Reputation: 213
I think you could implement an error decoder and catch the thrown exception inside an @ControllerAdvice
. This way, you could define your POJO (which has payment_uuid
field) in ResponseEntity<T>
without worrying about the error description, because it'll be handled by the error decoder.
Upvotes: 1