Hi,
in the last time I stumbled over the exception Handling in GH several times.
My problem is twofold:
- Error messages are not translated
- Recognizing an Error in the Frontend requires to parse the string
Therefore, I propose to create Classes for the most common Exceptions in GH, for example the “Cannot find Point”. Now we could add that class to the detail part of the json:
{
hints: [
{
details: "java.lang.IllegalArgumentException",
message: "Cannot find point 2: 57.326521,118.828125"
}
],
message: "Cannot find point 2: 57.326521,118.828125"
}
This would allow us to also create the correct Exception class in the Api:
https://github.com/graphhopper/directions-api-java-client/blob/master/client/src/main/java/com/graphhopper/api/GraphHopperWeb.java#L362
Additionally we might also think about translating the Error message, or reduce the message content. For example with the “Cannot find point” exception, we could only add the index of the point in the message. This would allow a Frontend developer to create a nice message like: “Hey mate, wapoint 1 seems to be placed over an area without a street”. Since he/she only needs to read the String and put the number of the missing point into the translation.
I think doing this for the most common Errors would be enough.
Best,
Robin