Почему пользовательский обработчик ошибок REST не вызывается, когда шаблон REST бросает исключение?JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Почему пользовательский обработчик ошибок REST не вызывается, когда шаблон REST бросает исключение?

Сообщение Anonymous »

Я пытаюсь охватить все остальные шаблонные вызовы в моем классе для обработки исключений. Использование пользовательской обработки исключений с помощью обработчика ошибок в приложении Spring Boot.public class BaseConfig {
@Bean
@Primary
RestTemplate restTemplate(@Autowired RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.errorHandler(new IPSRestErrorHandler()).build();
}
}
< /code>

@Component
public class IPSRestErrorHandler extends DefaultResponseErrorHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(IPSRestErrorHandler.class);

@Override
public void handleError(ClientHttpResponse response) throws IOException {
if (response.getStatusCode()
.series() == HttpStatus.Series.SERVER_ERROR) {
LOGGER.error("Server error with exception code : "+response.getStatusCode()+" with message : "+response.getStatusText());
throw ExceptionUtils.newRunTimeException("Server error with exception code : "+response.getStatusCode()+" with message : "+response.getStatusText());
} else if (response.getStatusCode()
.series() == HttpStatus.Series.CLIENT_ERROR) {
LOGGER.error("Client error with exception code : "+response.getStatusCode()+" with message : "+response.getStatusText());
throw ExceptionUtils.newRunTimeException("Client error with exception code : "+response.getStatusCode()+" with message : "+response.getStatusText());
} else {
LOGGER.error("Unknown HttpStatusCode with exception code : "+response.getStatusCode()+" with message : "+response.getStatusText());
throw ExceptionUtils.newRunTimeException("Unknown HttpStatusCode with exception code : "+response.getStatusCode()+" with message :"+response.getStatusText());
}
}
}
< /code>

public class ServicingPlatformSteps {

@Autowired
private RestTemplate restTemplate;

private ResponseEntity callServicingPlatformAPI(RemittanceV2Input inputClass) {
ResponseEntity entity = null;
entity = restTemplate.exchange(builder.build().encode().toUri(),
org.springframework.http.HttpMethod.POST, httpEntity, typeRef);
return entity;
}
< /code>

Here i am expecting that when restTemplate.exchange method is called and it throws some exception then my IPSRestErrorHandler should be called. But error handler is not getting called. While i am getting this restTemplate instance with error handler info in it.

Could you please help me why error handler is not getting called?

Подробнее здесь: https://stackoverflow.com/questions/556 ... -throw-exc
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»