use of eu.bcvsolutions.idm.core.api.exception.ErrorModel in project CzechIdMng by bcvsolutions.
the class RestErrorAttributes method getErrorAttributes.
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
Throwable error = getError(webRequest);
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace);
//
ErrorModel errorModel = null;
if (error instanceof ResultCodeException) {
errorModel = ((ResultCodeException) error).getError().getError();
} else {
if (errorAttributes.containsKey(ATTRIBUTE_STATUS)) {
int status = (int) errorAttributes.get(ATTRIBUTE_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;
}
errorAttributes.put(ATTRIBUTE_ERROR, errorModel);
LOG.warn(errorModel.toString());
//
return errorAttributes;
}
use of eu.bcvsolutions.idm.core.api.exception.ErrorModel in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyServiceIntegrationTest method checkMaxHistorySimilarError.
private void checkMaxHistorySimilarError(ResultCodeException exception, int maxHistorySettingOriginal) {
ErrorModel error = exception.getError().getError();
assertTrue(error.getMessage().contains("Password does not match password policy"));
assertEquals(CoreResultCode.PASSWORD_DOES_NOT_MEET_POLICY.getCode(), error.getStatusEnum());
Map<String, Object> parameters = error.getParameters();
assertEquals(1, parameters.size());
assertTrue(parameters.containsKey("maxHistorySimilar"));
Object parameterAsObject = parameters.get("maxHistorySimilar");
int maxHistorySetting = Integer.valueOf(parameterAsObject.toString());
assertEquals(maxHistorySettingOriginal, maxHistorySetting);
}
Aggregations