Spring Rest Client Exception Handling

后端 未结 2 457
暖寄归人
暖寄归人 2021-02-08 11:09

I am using spring RestTemplate to consume rest services(exposed in spring rest). I am able to consume success scenarios. But for negative scenarios, service returns

相关标签:
2条回答
  • 2021-02-08 11:31

    I found solution. HttpClientErrorException worked for me.

    It has e.getResponseBodyAsString() function which returns ResponseBody.

    0 讨论(0)
  • 2021-02-08 11:38

    You might want to distinguish between:

    HttpClientErrorException (HTTP-Status >=400) or HttpServerErrorException (HTTP-Status >= 500) or even RestClientException.

    Further on there is a good doc about defining your own ErrorHandler, see this link

    0 讨论(0)
提交回复
热议问题