smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.04k stars 273 forks source link

Add support for fallback providers #173

Open nikolauskrismer opened 6 years ago

nikolauskrismer commented 6 years ago

Just had the issue that nominatim was not reachable.

I was wondering if it is possible to catch such errors and fallback to other providers in that case (or to catch the error and show some message)

I did not find anything that would relate to such problems in the code, but maybe I am missing something... if so, I guess it would be a good idea to add a small sample to the docs :-)

jeafreezy commented 4 years ago

HI @nikolauskrismer , thanks for opening this issue. Please may I know how you solved this issue? I'm currently experiencing a similar error with nominatim. Thanks

yznts commented 4 years ago

@jeafreezy To be honest, I don't think that original issue will be the same as yours. Just describe your problem here a bit wider. Providing demo (like JSFiddle) will be awesome.

@smeijer I think "Providers fallback" will be good title for this issue, don’t you think? Also, it maybe related to issue https://github.com/smeijer/leaflet-geosearch/issues/153 (in both case we are manipulating with multiple providers)

smeijer commented 4 years ago

Yeah, I think this "error handling" should be solved by wrapping one or more providers. See also https://github.com/smeijer/leaflet-geosearch/issues/153#issuecomment-348686251.

The docs have an example on how to use a single provider directly. That one should be extended with searching in the fallback provider, if the first doesn't have results.

https://smeijer.github.io/leaflet-geosearch/usage#using-the-providers-directly

That being said, I doubt that provider 2 will have results, when provider 1 doesn't. Thereby, I don't really feel for adding native support for that.

I'm willing to reconsider if someone can come up with concrete examples of "x has no results for ..., but provider y has".

jeafreezy commented 4 years ago

Thank you @yuriizinets for the swift response. Unfortunately, I didn't take a screenshot of the error, but the error code was 400. My search box was making a request using the OpenStreetMaps provider and at that time the server was returning an error code. It's working fine now but my concern is that this should not happen in production and if at all it does, is there away I can catch such an error so I can display to the users some text e.g "THe server is down at the moment,kindly check back later" . Thanks

smeijer commented 4 years ago

We currently don't have a handler for those kind of errors. That's something that should definitely be added. I've created #245 to cover that change.

jeafreezy commented 4 years ago

Thank you @smeijer !