X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=lib%2FAPI.php;h=1fd3da011150fdfa0c3d20216b69da24a95553df;hp=ba384c5ad4eb0d591ebc3a1aa671099b841214b9;hb=3958595e9ff27162ae918db1453ddecd4840d481;hpb=21ffa2d775c959694776ee3f46f4e2d010a91e72 diff --git a/lib/API.php b/lib/API.php index ba384c5..1fd3da0 100644 --- a/lib/API.php +++ b/lib/API.php @@ -3,6 +3,7 @@ namespace seekat; use Countable; +use Exception; use Generator; use http\{ Client, @@ -155,10 +156,16 @@ class API implements IteratorAggregate, Countable { } /* fetch resource, unless already localized, and try for {$method}_url */ - return $this->$method->get(...$args)->otherwise(function(Throwable $error) use($method, $args) { + return $this->$method->get(...$args)->otherwise(function($error) use($method, $args) { + if ($error instanceof Throwable) { + $message = $error->getMessage(); + } else { + $message = $error; + $error = new Exception($error); + } if ($this->exists($method."_url", $url)) { - $this->__log->info(__FUNCTION__."($method): ". $error->getMessage(), [ + $this->__log->info(__FUNCTION__."($method): ". $message, [ "url" => (string) $this->__url ]); @@ -166,7 +173,7 @@ class API implements IteratorAggregate, Countable { return $this->withUrl($url)->get(...$args); } - $this->__log->error(__FUNCTION__."($method): ". $error->getMessage(), [ + $this->__log->error(__FUNCTION__."($method): ". $message, [ "url" => (string) $this->__url ]);