How do I retrieve HTTP status code and response body when an RestClientException is thrown?

前端 未结 4 686
眼角桃花
眼角桃花 2020-12-17 08:27

The methods of RestTemplate such as postForEntity() throw RestClientException. I would like to extract the HTTP status code and respon

4条回答
  •  隐瞒了意图╮
    2020-12-17 09:03

    Catch RestClientResponseException instead. It's more generic.

    From the docs: Common base class for exceptions that contain actual HTTP response data.

提交回复
热议问题