Вываливается стектрейс, не попадая в @RestControllerAdvice
HttpResponse response;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
response = httpClient.execute(httpPost);
if (response != null && response.getStatusLine() != null)//валится ошибка UnknownHostException
}catch(UnknownHostException e){
throw new ResourceNotFoundException(e.getMessage);
}
Добрый день, уважаемые коллеги разработчики, проблема у меня возникла такая: вываливается стектрейс с ResourceNotFoundException ошибкой, она почему - то не отлавливается в ControllerAdvice, в чем может быть проблема?
ResourceNotFoundException обработка в ControllerAdvice имеется
Используется: @RestControllerAdvice
ControllerAdvice:
@RestControllerAdvice
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(ResourceNotFoundException.class)
protected ResponseEntity<Object> handleResourceNotFound(ResourceNotFoundException ex) {
return buildResponseEntity(ex.getMessage());
}
private ResponseEntity<Object> buildResponseEntity(ErrorResult apiError) {
return new ResponseEntity<>(apiError, apiError.getStatus());
}
@Data
@AllArgsConstructor
private static class ErrorResult {
private int code;
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private LocalDateTime timestamp;
private String message;
private String debugMessage;
private String messageInfo;
private ErrorResult() {
timestamp = LocalDateTime.now();
}
ErrorResult(HttpStatus status) {
this();
this.status = status;
this.code = status.value();
}
ErrorResult(HttpStatus status, Throwable ex) {
this();
this.status = status;
this.message = "Unexpected error";
this.debugMessage = ex.getLocalizedMessage();
}
ErrorResult(HttpStatus status, String message, Throwable ex) {
this();
this.status = status;
this.message = message;
this.debugMessage = ex.getLocalizedMessage();
}
}
}
Если что-то не понятно в моем вопросе, пишите об этом в комментарии, поправлю