use of py.org.fundacionparaguaya.pspserver.common.dtos.ErrorDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleGeneralUncaughtExcption.
/**
* <p>
* Any other unhandled exceptions are processed here.
* </p>
* <p>
* We also process user defined (non standard) exceptions annotated with @ResponseStatus.
* See {@link py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException}
* </p>
* @param ex
* @return
*/
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleGeneralUncaughtExcption(Exception ex) {
HttpStatus status;
ErrorDTO errorDto;
ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
if (responseStatus != null) {
status = responseStatus.value();
errorDto = ErrorDTO.of(responseStatus.reason(), ex.getLocalizedMessage()).formatWithCode();
} else {
status = HttpStatus.INTERNAL_SERVER_ERROR;
errorDto = ErrorDTO.of(ErrorCodes.INTERNAL_SERVER_ERROR.getMessage(), ex.getLocalizedMessage()).formatWithCode();
}
LOG.error("Error id: {}", errorDto.getErrorId());
LOG.error(ex.getMessage(), ex);
return generateResponseEntity(errorDto, status);
}
use of py.org.fundacionparaguaya.pspserver.common.dtos.ErrorDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleCustomParameterizedValidationError.
@ExceptionHandler(CustomParameterizedException.class)
public ResponseEntity<Object> handleCustomParameterizedValidationError(CustomParameterizedException ex) {
List<FieldErrorDTO> fieldErrors = ex.getFieldErrors();
ErrorDTO dto = ErrorDTO.of(ex.getLocalizedMessage());
dto.addFieldErrors(fieldErrors);
return generateResponseEntity(dto, HttpStatus.BAD_REQUEST);
}
use of py.org.fundacionparaguaya.pspserver.common.dtos.ErrorDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleMethodArgumentNotValid.
/**
* <p>
* Errors thrown in Controllers methods with arguments annotated with JAX-RS @Valid.
* </p>
*
* @param ex
* @return
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
BindingResult result = ex.getBindingResult();
List<FieldError> fieldErrors = result.getFieldErrors();
ErrorDTO dto = ErrorDTO.of(fieldErrors, ErrorCodes.VALIDATION_FAILURE.getMessage(), ex.getLocalizedMessage());
return generateResponseEntity(dto, HttpStatus.BAD_REQUEST);
}
use of py.org.fundacionparaguaya.pspserver.common.dtos.ErrorDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleBusinessValidationError.
/**
* <p>
* Errors thrown in service layers validations, using standard exceptions.
* </p>
* <p>
* We favor the use of standard exceptions as recommended in:
* https://github.com/tatsuyaoiw/effective-java/blob/master/chapter-9.md#item-60-favor-the-use-of-standard-exceptions
* </p>
* @param ex
* @return
*/
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<Object> handleBusinessValidationError(IllegalArgumentException ex) {
LOG.debug(ex.getMessage(), ex);
ErrorDTO dto = ErrorDTO.of(ex.getLocalizedMessage());
return generateResponseEntity(dto, HttpStatus.BAD_REQUEST);
}
Aggregations