use of org.springframework.web.bind.annotation.ExceptionHandler in project arch-playground by BeneStem.
the class ExceptionHandlerHtmlControllerAdvice method handleConstraintViolation.
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView handleConstraintViolation(final ConstraintViolationException exception) {
final MappingJackson2JsonView view = new CustomMappingJackson2JsonView();
final var modelAndView = new ModelAndView(view);
modelAndView.addObject(exception.getConstraintViolations().stream().map(constraintViolation -> new ValidationError(((PathImpl) constraintViolation.getPropertyPath()).getLeafNode().getName(), constraintViolation.getMessage())).collect(toList()));
return modelAndView;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project rpki-validator-3 by RIPE-NCC.
the class ApiErrorHandler method handleDataRetrievalFailureException.
@ExceptionHandler(value = DataRetrievalFailureException.class)
protected ResponseEntity<ApiResponse<?>> handleDataRetrievalFailureException(DataRetrievalFailureException ex, WebRequest request) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.valueOf(Api.API_MIME_TYPE));
return new ResponseEntity<>(ApiResponse.error(ApiError.of(HttpStatus.NOT_FOUND)), headers, HttpStatus.NOT_FOUND);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project SONG by overture-stack.
the class ServerExceptionHandler method handleAccessDeniedException.
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<String> handleAccessDeniedException(HttpServletRequest request, HttpServletResponse response, AccessDeniedException ex) {
val rootCause = getRootCause(ex);
val error = SongError.builder().requestUrl(generateRequestUrlWithParams(request)).timestamp(System.currentTimeMillis()).httpStatusCode(UNAUTHORIZED_TOKEN.getHttpStatus().value()).httpStatusName(UNAUTHORIZED_TOKEN.getHttpStatus().name()).errorId(UNAUTHORIZED_TOKEN.getErrorId()).message(ex.getMessage()).debugMessage(format("[ROOT_CAUSE] -> %s: %s", rootCause.getClass().getName(), rootCause.getMessage())).stackTrace(getFullStackTraceList(ex)).build();
log.error(error.toPrettyJson());
return error.getResponseEntity();
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project SONG by overture-stack.
the class ServerExceptionHandler method handleThrowable.
@ExceptionHandler(Throwable.class)
public ResponseEntity<String> handleThrowable(HttpServletRequest request, HttpServletResponse response, Throwable ex) {
val rootCause = getRootCause(ex);
val error = SongError.builder().requestUrl(generateRequestUrlWithParams(request)).timestamp(System.currentTimeMillis()).httpStatusCode(UNKNOWN_ERROR.getHttpStatus().value()).httpStatusName(UNKNOWN_ERROR.getHttpStatus().name()).errorId(UNKNOWN_ERROR.getErrorId()).message(ex.getMessage()).debugMessage(format("[ROOT_CAUSE] -> %s: %s", rootCause.getClass().getName(), rootCause.getMessage())).stackTrace(getFullStackTraceList(ex)).build();
log.error(error.toPrettyJson());
return error.getResponseEntity();
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project flytecnologia-api by jullierme.
the class FlyExceptionHandler method handleDataIntegrityViolationException.
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<Object> handleDataIntegrityViolationException(DataIntegrityViolationException ex, WebRequest request) {
String fieldError = "resource.operation-not-allowed";
if (ex.getCause() instanceof ConstraintViolationException) {
fieldError = ((ConstraintViolationException) ex.getCause()).getConstraintName();
}
List<Error> errors = getListOfErros(fieldError, ex);
return handleExceptionInternal(ex, errors, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
Aggregations