从 422 无法处理的实体中获取自定义响应 JSON

Get the customized Response JSON from 422 Unprocessable Entity

我有一个 Java 调用第三方 API 的 Springboot 微服务。对于我的一个测试用例,API returns 422 Unprocessable entity with a customized Response JSON Body

{
    "request_status": "error",
    "status": "error",
    "requested_url": "www.example.de",
    "url": "http://www.newexample.de/",
    "issue": "redirect",
    "recommendedUrl": true,
    "error_message": "The web address you entered redirects to another website."
}

我无法在我的微服务中检索此响应正文。我的代码如下

try {
    HttpEntity<Input_Class> httpentity = new HttpEntity<Input_Class>(                      inputClassObj, headers);
    responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpentity,
         new ParameterizedTypeReference<Output_Class>() {});

} catch(RestClientException ue) {
     if (ue instanceof HttpStatusCodeException) {
         String errorResponse = ((HttpStatusCodeException) ue).getResponseBodyAsString();
         logger.info(errorResponse);
}

我在日志中看到的错误响应是

{
    "status": "ERROR",
    "errorMessage": "Unprocessable Entity"
}

谁能告诉我应该使用哪个异常 class 来获取 API 发送的响应正文。

    catch(RestClientException ue) {
     if (ue instanceof HttpStatusCodeException) {
         String errorResponse = ((HttpStatusCodeException) ue).getResponseBodyAsString();
         logger.info(errorResponse);
}

这个代码块确实有效。 errorResponse returns 响应 JSON。我正在使用另一个终结响应的端点 url,因此没有得到实际响应。