use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionUtilsUnitTest method testLogModelLevelDebug.
@Test
public void testLogModelLevelDebug() {
ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.ACCEPTED), new CoreException("mock"));
// error is logged without model is specified
verify(LOG).debug(any(String.class), any(Exception.class));
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionUtilsUnitTest method testLogModelWithoutException.
@Test
public void testLogModelWithoutException() {
ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR), null);
// error is logged without model is specified
verify(LOG).error(any(String.class), (Throwable) ArgumentMatchers.isNull());
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionUtilsUnitTest method testLogExceptionLevelWarn.
@Test
public void testLogExceptionLevelWarn() {
ExceptionUtils.log(LOG, new ResultCodeException(new DefaultErrorModel(CoreResultCode.FORBIDDEN)));
// error is logged without model is specified
verify(LOG).warn(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(IdmAuthenticationException.class)
public 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());
}
use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(PersistenceException.class)
public 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());
}
Aggregations