GHErrors Messages - Translation - Recognition

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

1 Like

This sounds good. Although I’m (for now :)) against translating error messages. But I think we could solve this differently e.g. exposing the information in a computer readable format like returning the problematic location index in a separate field.

Thanks :slight_smile:.

Ok, how would we do this for the “Cannot find point” exception?

My approahc would be something like: create a Class that extends from IllegalArgumentException. Add a integer to it that represents the index. When creating this exception we set this integer and also parse that field into the JSON. When deserializing it in the Api Client we would also read this field for the CannotFindPointException class.

We could store a separate problematic_indices array in the hints?

My approahc would be something like: create a Class that extends from IllegalArgumentException

Or something like this, yes.

1 Like

Ok nice, I will create a PR for this in the next time :slight_smile: