Search in sources :

Example 1 with DetailedIllegalArgumentException

use of com.graphhopper.util.exceptions.DetailedIllegalArgumentException 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;
}
Also used : PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) GHPoint(com.graphhopper.util.shapes.GHPoint) ConnectionNotFoundException(com.graphhopper.util.exceptions.ConnectionNotFoundException) DetailedRuntimeException(com.graphhopper.util.exceptions.DetailedRuntimeException) JSONObject(org.json.JSONObject) DetailedIllegalArgumentException(com.graphhopper.util.exceptions.DetailedIllegalArgumentException) PointOutOfBoundsException(com.graphhopper.util.exceptions.PointOutOfBoundsException) DetailedRuntimeException(com.graphhopper.util.exceptions.DetailedRuntimeException)

Aggregations

ConnectionNotFoundException (com.graphhopper.util.exceptions.ConnectionNotFoundException)1 DetailedIllegalArgumentException (com.graphhopper.util.exceptions.DetailedIllegalArgumentException)1 DetailedRuntimeException (com.graphhopper.util.exceptions.DetailedRuntimeException)1 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)1 PointOutOfBoundsException (com.graphhopper.util.exceptions.PointOutOfBoundsException)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1