Geocoder icon indicating copy to clipboard operation
Geocoder copied to clipboard

Chain Provider catch Exception

Open georgecoca opened this issue 6 years ago • 7 comments

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.

georgecoca avatar Aug 24 '18 14:08 georgecoca

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.

holtkamp avatar Apr 30 '19 12:04 holtkamp

Submitted a PR for the ability to configure the log level: https://github.com/geocoder-php/Geocoder/pull/950

holtkamp avatar Apr 30 '19 12:04 holtkamp

@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 avatar May 10 '19 00:05 chriscalip

@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.

georgecoca avatar May 10 '19 15:05 georgecoca

@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.

chriscalip avatar May 10 '19 20:05 chriscalip

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.

atymic avatar Jun 02 '19 01:06 atymic

PR open in #978 with a potential solution.

atymic avatar Jul 01 '19 01:07 atymic