Search in sources :

Example 1 with DefaultErrorModel

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

the class RestErrorAttributes method getErrorAttributes.

@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
    Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
    ErrorModel errorModel = null;
    if (errorAttributes.containsKey("status")) {
        int status = (int) errorAttributes.get("status");
        switch(status) {
            case 401:
                {
                    errorModel = new DefaultErrorModel(CoreResultCode.LOG_IN, ImmutableMap.of("path", errorAttributes.get("path")));
                    break;
                }
            case 403:
                {
                    errorModel = new DefaultErrorModel(CoreResultCode.FORBIDDEN, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                    break;
                }
            case 404:
                {
                    errorModel = new DefaultErrorModel(CoreResultCode.ENDPOINT_NOT_FOUND, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                    break;
                }
            case 400:
            case 405:
                {
                    errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                    break;
                }
            default:
                {
                    errorModel = null;
                }
        }
    }
    if (errorModel == null) {
        log.error("Error not resolved - errorAttributes needs extension for error attrs [{}]", errorAttributes);
        return errorAttributes;
    }
    // we need timestamp etc.
    // errorAttributes.clear();
    errorAttributes.put("error", errorModel);
    log.warn(errorModel.toString());
    return errorAttributes;
}
Also used : DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)

Example 2 with DefaultErrorModel

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

the class ScriptRedeployBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    ResultModels results = super.prevalidate();
    // 
    // add info message about classpath
    String redeployFolder = getConfigurationService().getValue(IdmScriptService.SCRIPT_FOLDER);
    if (StringUtils.isNotEmpty(redeployFolder)) {
        ResultModel result = new DefaultErrorModel(CoreResultCode.DEPLOY_SCRIPT_FOLDER_FOUND, ImmutableMap.of("redeployFolder", redeployFolder));
        results.addInfo(result);
    }
    return results;
}
Also used : ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 3 with DefaultErrorModel

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

the class AsyncConfig method getAsyncUncaughtExceptionHandler.

@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
    // simple error logging
    return new AsyncUncaughtExceptionHandler() {

        @Override
        public void handleUncaughtException(Throwable throwable, Method method, Object... obj) {
            if (throwable instanceof ResultCodeException) {
                ResultCodeException ex = (ResultCodeException) throwable;
                LOG.error("[" + ex.getId() + "] ", ex);
            } else {
                ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, throwable.getMessage());
                LOG.error("[" + errorModel.getId() + "] ", throwable);
            }
        }
    };
}
Also used : AsyncUncaughtExceptionHandler(org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) Method(java.lang.reflect.Method) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)

Example 4 with DefaultErrorModel

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

the class ExceptionUtilsUnitTest method testExceptionLevelDebug.

@Test
public void testExceptionLevelDebug() {
    ExceptionUtils.log(LOG, new ResultCodeException(new DefaultErrorModel(CoreResultCode.ACCEPTED)));
    // error is logged without model is specified
    verify(LOG).debug(any(String.class), any(Exception.class));
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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)

Example 5 with DefaultErrorModel

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

the class ExceptionUtilsUnitTest method testLogExceptionLevelError.

@Test
public void testLogExceptionLevelError() {
    ExceptionUtils.log(LOG, new ResultCodeException(new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR)));
    // error is logged without model is specified
    verify(LOG).error(any(String.class), any(Exception.class));
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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