Api1 в одном модуле вызывает Api2 другого модуля, Api2 вызывает пользовательское исключение.
responseEntity = apiCallService.callApi(url, requestEntity, HttpMethod.POST);
Api2 if(bankTerminalList.isEmpty()) {
logger.info("no recors found.");
throw new RecordNotFoundException("Can not find a recod with btid - "+reqDto.getBtid()+", utid - "+reqDto.getUtid()+" and acq bank code "+reqDto.getAcqBankCode(), "6587");
CustomizedResponseEntityExceptionHandler
@ ControllerAdvice
@RestController
открытый класс CustomizedResponseEntityExceptionHandler расширяет ResponseEntityExceptionHandler {
@ExceptionHandler(Exception.class)
public final ResponseEntity<OnboardingExceptionResponse> handleAllExceptions(Exception ex, WebRequest request) {
Map<String, Object> subResponse = new HashMap<>();
subResponse.put("requestType", request.getDescription(false));
OnboardingExceptionResponse exceptionResponse = new OnboardingExceptionResponse("01", ex.getMessage(),subResponse);
ex.printStackTrace();
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(RecordNotFoundException.class)
public final ResponseEntity<Object> RecordNotFoundException(RecordNotFoundException ex, WebRequest request) {
Map<String, Object> subResponse = new HashMap<>();
subResponse.put("requestType", request.getDescription(false));
OnboardingExceptionResponse exceptionResponse = new OnboardingExceptionResponse(ex.getErrorCode(),ex.getMessage(), subResponse);
return new ResponseEntity<Object>(exceptionResponse, HttpStatus.NOT_FOUND);
}
@ExceptionHandler(DatabaseException.class)
public final ResponseEntity<OnboardingExceptionResponse> handleUserNotFoundException(DatabaseException ex, WebRequest request) {
Map<String, Object> subResponse = new HashMap<>();
subResponse.put("requestType", request.getDescription(false));
OnboardingExceptionResponse exceptionResponse = new OnboardingExceptionResponse(ex.getErrorCode(),"DatabaseException " + ex.getMessage(), subResponse);
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@ResponseStatus(HttpStatus.NOT_FOUND)
открытый класс RecordNotFoundException расширяет RuntimeException {
private static final long serialVersionUID = -8167456049549125128L;
String errorCode = "01";
public RecordNotFoundException(String exception, String errorCode) {
super(exception);
this.errorCode = errorCode;
}
public String getErrorCode() {
return errorCode;
}
}
Я получаю responseEntity как ноль в Api1.
При самостоятельном вызове Api2 я получаю действительный ответ, как
{
"responseCode": "6587",
"responseMessage": "Can not find a recod with btid - 87651222, utid - L0000101s and acq bank code 05",
"responseDetails": {
"requestType": "uri=/btid//updateBatchStanInvoice"
}
}