use of io.crnk.core.engine.error.ExceptionMapper in project crnk-framework by crnk-project.
the class ExceptionMapperRegistry method findMapperFor.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <E extends Throwable> Optional<ExceptionMapper<E>> findMapperFor(ErrorResponse errorResponse) {
int currentDepth = -1;
ExceptionMapper closestExceptionMapper = null;
for (ExceptionMapperType mapperType : exceptionMappers) {
JsonApiExceptionMapper mapperObj = mapperType.getExceptionMapper();
if (mapperObj instanceof ExceptionMapper) {
ExceptionMapper mapper = (ExceptionMapper) mapperObj;
boolean accepted = mapper.accepts(errorResponse);
if (accepted) {
// the exception with the most super types is chosen
int tempDepth = countSuperTypes(mapperType.getExceptionClass());
if (tempDepth > currentDepth) {
currentDepth = tempDepth;
closestExceptionMapper = mapper;
}
}
}
}
return (Optional) Optional.ofNullable(closestExceptionMapper);
}
Aggregations