Closed dernewt closed 1 year ago
Thank you for the detailed ticket!
I agree that in cases of a 404 response, it is best to return an empty set, since that is what the 404 represents. I will make an update to fix this issue.
I am more concerned about the fact that this probably means other "bad" responses coming from the geocoding APIs are not properly being handled and returned in the exception, which would definitely be confusing.
I will try to release a fix/update for this ASAP.
@dernewt So digging into this a little bit, the issue might be slightly different that you were thinking.
I wasn't able to reproduce it immediately. Sending a request to with a non-existent place, I get back and empty result from MapBox, as one would expect.
Raw request:
https://api.mapbox.com/geocoding/v5/mapbox.places/NONEXISTENTPLACE.json?autocomplete=true&fuzzyMatch=true&limit=1&routing=false&access_token=TOKEN
I get back the response
{
"type":"FeatureCollection",
"query":[
"nonexistentplace"
],
"features":[
],
"attribution":"NOTICE: © 2022 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
Which is what I would expect. This is properly mapped and returns a correct response from the library.
It wasn't until I passed an "invalid" character (like you mentioned in https://github.com/JustinCanton/Geo.NET/issues/43), that I got a bad request.
Raw request:
https://api.mapbox.com/geocoding/v5/mapbox.places/?autocomplete=true&fuzzyMatch=true&limit=1&routing=false&access_token=TOKEN#.json
You will notice that the #.json
is at the end of the string, which is unexpected, and like you mentioned, being caused by the URL builder. Sending this request, I get back the response
"{\"message\":\"Not Found\"}"
My assumption is this will be fixed once the uri is properly created and there is some method of handling # characters.
All of this said, the exception that is thrown does in fact contain a bit of information about the exception. It has the response body at the moment:
I will expand a bit on the exception and what information it has, as well as the logging of the exception to actually display the data that it contains. But the main fix for this will have to be a part of https://github.com/JustinCanton/Geo.NET/issues/43.
Whoops, sorry for the bad scenario, good catch on the actual problem. Overall really great repo btw.
When a query to MapBox returns 0 results the library isn't handling it gracefully.
To Reproduce using nuget Geo.MapBox 1.1.1
Call Mapbox.GeocodingAsync with some query that returns no results.
Raw request:
Raw response
The library throws an exception with no exception data or inner exception.
Expected behavior One of the following in order of preference (you should probably standardize the "no result" response across your other providers: