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;
}
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;
}
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);
}
}
};
}
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));
}
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));
}
Aggregations