use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionUtilsUnitTest method testLogModelLevelError.
@Test
public void testLogModelLevelError() {
ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR), new CoreException("mock"));
// error is logged without model is specified
verify(LOG).error(any(String.class), any(Exception.class));
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(DataIntegrityViolationException.class)
public 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 if (constraintEx.getConstraintName() == null) {
errorModel = new DefaultErrorModel(CoreResultCode.CONFLICT, ImmutableMap.of("name", "..."));
} else {
errorModel = new DefaultErrorModel(CoreResultCode.CONFLICT, ImmutableMap.of("name", StringUtils.trimToEmpty(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());
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(Exception.class)
public ResponseEntity<ResultModels> handle(Exception ex) {
Throwable cause = Throwables.getRootCause(ex);
// If is cause instance of ResultCodeException, then we will log exception and throw only ResultCodeException (for better show on frontend)
if (cause instanceof ResultCodeException) {
return handle((ResultCodeException) cause);
} else {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, ex.getMessage());
ExceptionUtils.log(LOG, errorModel, ex);
//
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(CoreException.class)
public ResponseEntity<ResultModels> handle(CoreException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, ex.getMessage(), ex.getDetails());
LOG.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ResultModels> handle(HttpMessageNotReadableException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ex.getMessage());
LOG.warn("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Aggregations