westnordost / osmapi

Java client for the OSM API 0.6
GNU Lesser General Public License v3.0
97 stars 19 forks source link

store query in exception that caused error #16

Closed matkoniecz closed 6 years ago

matkoniecz commented 6 years ago

In case of 400 error (malformed query) it is usually useful to have text of executed query

I think that osmapi should add query text to exception data on encountering 400 code in Overpass response

In https://github.com/westnordost/StreetComplete/pull/954 I tried adding it to StreetComplete, but I think that it would be better to add it here.

matkoniecz commented 6 years ago

It would be useful also for timeouts.

westnordost commented 6 years ago

The library already puts any information it gets from the HTTP error response into the exception, see OsmConnection line 333-345. Overpass in this case outputs an error message that includes the query and a pointer to what went wrong. So, this already works. See i.e. http://overpass-turbo.eu/s/xK8

Also, the actual query string is still on the stack when an exception is thrown. I.e.

String myFaultyQuery = "what??";
OverpassMapDataDao dao;
try {
  dao.get(myFaultyQuery,  (element, geometry) ->{ /* nevermind */ });
} catch(OsmApiException e) {
  System.out.println("Oh hey, lets have a look at the query: " + myFaultyQuery);
  System.out.println("But actually, this is more interesting: " + e.getDescription());
}