@@ -59,7 +59,7 @@ public function __construct($apiKey, ClientAdapterInterface $adapter = null)
5959 {
6060 self ::$ apiKey = $ apiKey ;
6161 if (is_null ($ adapter )) {
62- if (class_exists ('GuzzleHttp\Client ' ,false )) {
62+ if (class_exists ('GuzzleHttp\Client ' ,true )) {
6363 $ adapter = new GuzzleClientAdapter ();
6464 }else {
6565 $ adapter = new FileGetContentsClientAdapter ();
@@ -80,8 +80,9 @@ public function __construct($apiKey, ClientAdapterInterface $adapter = null)
8080 */
8181 public function getForecast ($ latitude , $ longitude , \DateTime $ time = null )
8282 {
83- $ response = $ this ->adapter ->getForecast ($ latitude ,$ longitude , $ time );
84- $ responseHeaders = $ this ->adapter ->getHeaders ();
83+ try {
84+ $ response = $ this ->adapter ->getForecast ($ latitude , $ longitude , $ time );
85+ $ responseHeaders = $ this ->adapter ->getHeaders ();
8586
8687 if (!is_null ($ responseHeaders ['apiCalls ' ])) {
8788 $ this ->apiCalls = $ responseHeaders ['apiCalls ' ];
@@ -94,7 +95,10 @@ public function getForecast($latitude, $longitude, \DateTime $time = null)
9495 $ cacheAge = (new \DateTime ())->getTimestamp () - (new \DateTime ($ responseHeaders ['cache ' ]['expires ' ]))->getTimestamp ();
9596 }
9697
97- return new Forecast ($ response ,$ cacheAge , $ responseHeaders ['responseTime ' ]);
98+ return new Forecast ($ response , $ cacheAge , $ responseHeaders ['responseTime ' ]);
99+ }catch (\Exception $ e ) {
100+ return null ;
101+ }
98102 }
99103
100104 /**
0 commit comments