use of com.graphhopper.util.exceptions.DetailedRuntimeException in project graphhopper by graphhopper.
the class GraphHopperWeb method readErrors.
public static List<Throwable> readErrors(JSONObject json) {
List<Throwable> errors = new ArrayList<>();
JSONArray errorJson;
if (json.has("message")) {
if (json.has("hints")) {
errorJson = json.getJSONArray("hints");
} else {
// should not happen
errors.add(new RuntimeException(json.getString("message")));
return errors;
}
} else
return errors;
for (int i = 0; i < errorJson.length(); i++) {
JSONObject error = errorJson.getJSONObject(i);
String exClass = "";
if (error.has("details"))
exClass = error.getString("details");
String exMessage = error.getString("message");
if (exClass.equals(UnsupportedOperationException.class.getName()))
errors.add(new UnsupportedOperationException(exMessage));
else if (exClass.equals(IllegalStateException.class.getName()))
errors.add(new IllegalStateException(exMessage));
else if (exClass.equals(RuntimeException.class.getName()))
errors.add(new DetailedRuntimeException(exMessage, toMap(error)));
else if (exClass.equals(IllegalArgumentException.class.getName()))
errors.add(new DetailedIllegalArgumentException(exMessage, toMap(error)));
else if (exClass.equals(ConnectionNotFoundException.class.getName())) {
errors.add(new ConnectionNotFoundException(exMessage, toMap(error)));
} else if (exClass.equals(PointNotFoundException.class.getName())) {
int pointIndex = error.getInt("point_index");
errors.add(new PointNotFoundException(exMessage, pointIndex));
} else if (exClass.equals(PointOutOfBoundsException.class.getName())) {
int pointIndex = error.getInt("point_index");
errors.add(new PointOutOfBoundsException(exMessage, pointIndex));
} else if (exClass.isEmpty())
errors.add(new DetailedRuntimeException(exMessage, toMap(error)));
else
errors.add(new DetailedRuntimeException(exClass + " " + exMessage, toMap(error)));
}
if (json.has("message") && errors.isEmpty())
errors.add(new RuntimeException(json.getString("message")));
return errors;
}
Aggregations