use of eu.bcvsolutions.idm.core.api.dto.ResultModels in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(Exception.class)
ResponseEntity<ResultModels> handle(Exception ex) {
Throwable cause = Throwables.getRootCause(ex);
// If is cause instance of ResultCodeException, then we will log catched exception and throw only ResultCodeException (for better show on frontend)
if (cause instanceof ResultCodeException) {
log.error(ex.getLocalizedMessage(), ex);
return handle((ResultCodeException) cause);
} else {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, ex.getMessage());
log.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
}
use of eu.bcvsolutions.idm.core.api.dto.ResultModels in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(PersistenceException.class)
ResponseEntity<ResultModels> handle(PersistenceException ex) {
ErrorModel errorModel = null;
//
if (ex.getCause() != null && ex.getCause() instanceof ConstraintViolationException) {
ConstraintViolationException constraintEx = (ConstraintViolationException) ex.getCause();
// TODO: registrable contstrain error codes
if (constraintEx.getConstraintName().contains("name")) {
errorModel = new DefaultErrorModel(CoreResultCode.NAME_CONFLICT, ImmutableMap.of("name", constraintEx.getConstraintName()));
} else if (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.getMessage());
}
log.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of eu.bcvsolutions.idm.core.api.dto.ResultModels in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(IdmAuthenticationException.class)
ResponseEntity<ResultModels> handle(IdmAuthenticationException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.AUTH_FAILED);
// source exception message is shown only in log
log.warn("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Aggregations