Я пытаюсь охватить все остальные шаблонные вызовы в моем классе для обработки исключений. Использование пользовательской обработки исключений с помощью обработчика ошибок в приложении 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
Почему пользовательский обработчик ошибок REST не вызывается, когда шаблон REST бросает исключение? ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Глобальный обработчик исключений отменяет обработчик транзакций базы данных
Anonymous » » в форуме JAVA - 0 Ответы
- 85 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Обработчик исключений Spring @Controller и глобальный обработчик исключений. Как вызвать оба
Anonymous » » в форуме JAVA - 0 Ответы
- 59 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Обработчик addUIInterruptionMonitor не вызывается для оповещения, связанного с фотографиями.
Anonymous » » в форуме IOS - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-