use of org.springframework.web.bind.annotation.ExceptionHandler in project entando-core by entando.
the class RestExceptionHandler method processRestRourceNotFoundEx.
@ExceptionHandler(value = RestRourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public RestResponse processRestRourceNotFoundEx(RestRourceNotFoundException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
RestResponse response = null;
if (null != ex.getBindingResult()) {
BindingResult result = ex.getBindingResult();
response = processAllErrors(result);
} else {
response = new RestResponse();
RestError error = new RestError(ex.getErrorCode(), this.resolveLocalizedErrorMessage("NOT_FOUND", new Object[] { ex.getObjectName(), ex.getObjectCode() }));
List<RestError> errors = new ArrayList<>();
errors.add(error);
response.setErrors(errors);
response.setMetaData(new HashMap<>());
}
return response;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project entando-core by entando.
the class RestExceptionHandler method processValidationError.
@ExceptionHandler(value = ValidationGenericException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public RestResponse processValidationError(ValidationGenericException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
BindingResult result = ex.getBindingResult();
RestResponse response = processAllErrors(result);
return response;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project entando-core by entando.
the class RestExceptionHandler method processEntandoTokenException.
@ExceptionHandler(value = EntandoTokenException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public RestResponse processEntandoTokenException(EntandoAuthorizationException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
RestResponse response = new RestResponse();
RestError error = new RestError(RestErrorCodes.UNAUTHORIZED, this.resolveLocalizedErrorMessage("UNAUTHORIZED", new Object[] { ex.getUsername(), ex.getRequestURI(), ex.getMethod() }));
List<RestError> errors = new ArrayList<>();
errors.add(error);
response.setErrors(errors);
return response;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project nikita-noark5-core by HiOA-ABI.
the class RestResponseEntityExceptionHandler method handleMalformedHeaderException.
@ExceptionHandler(NikitaMalformedHeaderException.class)
public ResponseEntity<Object> handleMalformedHeaderException(final RuntimeException ex, final WebRequest request) {
logger.error("400 Status Code", ex);
logger.error(request.getDescription(true), ex);
return handleExceptionInternal(ex, message(HttpStatus.BAD_REQUEST, ex), new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(DataIntegrityViolationException.class)
ResponseEntity<ResultModels> handle(DataIntegrityViolationException ex) {
ErrorModel errorModel = null;
//
if (ex.getCause() != null && ex.getCause() instanceof ConstraintViolationException) {
ConstraintViolationException constraintEx = (ConstraintViolationException) ex.getCause();
// TODO: registrable constraint error codes
if (constraintEx.getConstraintName() != null && constraintEx.getConstraintName().contains("name")) {
errorModel = new DefaultErrorModel(CoreResultCode.NAME_CONFLICT, ImmutableMap.of("name", constraintEx.getConstraintName()));
} else if (constraintEx.getConstraintName() != null && constraintEx.getConstraintName().contains("code")) {
errorModel = new DefaultErrorModel(CoreResultCode.CODE_CONFLICT, ImmutableMap.of("name", constraintEx.getConstraintName()));
} else {
errorModel = new DefaultErrorModel(CoreResultCode.CONFLICT, ImmutableMap.of("name", constraintEx.getConstraintName()));
}
} else {
errorModel = new DefaultErrorModel(CoreResultCode.CONFLICT, ex.getMostSpecificCause().getMessage());
}
log.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Aggregations