Geocoder
Geocoder copied to clipboard
Chain Provider catch Exception
Hi,
Currently, the chain provider only logs the exceptions, there is no way to catch the exceptions and we always get an empty AddressCollection
in case something went wrong. There is no way to know if the collection is empty because there were no results or if an error occurred.
A simple customized solution would be to extend the class Chain
and throw the exception but it's not possible since it's final
. All I can do is to replicate the class (not best solution).
If there is a workaround about this I would like to hear about it, otherwise I guess it must be implemented a way to catch the erros.
Thank you.
Also encountered this: currently it is not possible to influence how the ChainProvider deals with exceptions.
It would be nice to make it configurable to:
- rethrow caught Exceptions
- indicate the severity level of the logged exceptions, which is currently fixed at the
alert
level
Rationale
In a chain of Geocoders, one of them is not capable of geocoding IP-addresses. Ok, no problem, the next Geocoder in the chain might be able to do this. But this does result in a lot of alert
level exceptions. It would be nice to either decrease the level of logging, and/or rethrow the Exception so an UnsupportedOperation
could be caught and dealt with gracefully.
Submitted a PR for the ability to configure the log level: https://github.com/geocoder-php/Geocoder/pull/950
@geodeveloper Curious from quote "All I can do is to replicate the class (not best solution)." Why is not the best solution nor even a workable for your app? Whats wrong with creating a class implementing those interfaces?
@chriscalip it's not the best solution because you need to replicate the whole class when maybe you only need to override one method. Now on future releases I have to maintain this custom class myself if anything changes on all other methods.
@geodeveloper I see how about an alternative.. given that the interfaces wont be changing this major version; you can have a custom class with a composition of using the ChainProvider. On the custom class implementation methods call-in the ChainProvider .. oh wait logger needs to be in the ChainProvider method. Ok I got you.
What about if we catch exceptions as we currently do, and then rethrow a ChainException
which contains all of the exceptions encountered.
You'd then be able to loop over the caught exceptions and handle them as required.
PR open in #978 with a potential solution.