Search in sources :

Example 6 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel 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());
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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 7 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel 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());
}
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 8 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel 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());
}
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 9 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel 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 10 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel 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)

Aggregations

ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)17 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)14 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)11 HttpHeaders (org.springframework.http.HttpHeaders)11 ResponseEntity (org.springframework.http.ResponseEntity)11 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)2 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 Test (org.junit.Test)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)1 Method (java.lang.reflect.Method)1 AsyncUncaughtExceptionHandler (org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler)1