Search in sources :

Example 11 with DefaultErrorModel

use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.

the class ExceptionControllerAdvice method handle.

/**
 * Optimistic lock exception - convert to result code exception.
 *
 * @param ex
 * @return
 * @since 9.6.3
 */
@ExceptionHandler(ObjectOptimisticLockingFailureException.class)
public ResponseEntity<ResultModels> handle(ObjectOptimisticLockingFailureException ex) {
    ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.OPTIMISTIC_LOCK_ERROR, ex.getMessage(), ImmutableMap.of("entityType", String.valueOf(ex.getPersistentClassName()), "entityId", ex.getIdentifier() != null ? ex.getIdentifier().toString() : ""));
    LOG.warn("[" + errorModel.getId() + "] ", ex);
    return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 12 with DefaultErrorModel

use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.

the class ExceptionControllerAdvice method handle.

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ResultModels> handle(HttpRequestMethodNotSupportedException ex) {
    ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ex.getMessage(), // 
    ImmutableMap.of(// 
    "errorMethod", // 
    ex.getMethod(), "supportedMethods", StringUtils.join(ex.getSupportedMethods(), ", ")));
    LOG.warn("[" + errorModel.getId() + "] ", ex);
    return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 13 with DefaultErrorModel

use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.

the class ExceptionControllerAdvice method handle.

@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ResultModels> handle(AccessDeniedException ex) {
    ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.FORBIDDEN, ex.getMessage());
    LOG.warn("[" + errorModel.getId() + "] ", ex);
    return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 14 with DefaultErrorModel

use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.

the class AbstractBackupBulkAction method prevalidate.

@Override
@SuppressWarnings("unchecked")
public ResultModels prevalidate() {
    ResultModels results = new ResultModels();
    Recoverable<DTO> service = (Recoverable<DTO>) getService();
    String backupFolder = service.getBackupFolder();
    if (StringUtils.isEmpty(backupFolder)) {
        ResultModel result = new DefaultErrorModel(CoreResultCode.BACKUP_FOLDER_NOT_FOUND, ImmutableMap.of("property", Recoverable.BACKUP_FOLDER_CONFIG));
        results.addInfo(result);
    } else {
        ResultModel result = new DefaultErrorModel(CoreResultCode.BACKUP_FOLDER_FOUND, ImmutableMap.of("backupFolder", backupFolder));
        results.addInfo(result);
    }
    return results;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Recoverable(eu.bcvsolutions.idm.core.api.service.Recoverable)

Example 15 with DefaultErrorModel

use of eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel in project CzechIdMng by bcvsolutions.

the class ExceptionUtilsUnitTest method testLogModelLevelWarn.

@Test
public void testLogModelLevelWarn() {
    ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.FORBIDDEN), new CoreException("mock"));
    // error is logged without model is specified
    verify(LOG).warn(any(String.class), any(Exception.class));
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Aggregations

DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)24 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)14 ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)14 HttpHeaders (org.springframework.http.HttpHeaders)11 ResponseEntity (org.springframework.http.ResponseEntity)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)10 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)7 Test (org.junit.Test)7 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)6 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 Recoverable (eu.bcvsolutions.idm.core.api.service.Recoverable)1 Method (java.lang.reflect.Method)1 AsyncUncaughtExceptionHandler (org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler)1 HttpStatus (org.springframework.http.HttpStatus)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1