From ab7506b66f2c63188a540c04e22f6969ae538c12 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 4 Aug 2018 10:32:26 -0700 Subject: [PATCH] don't crash with an invalid api key --- controllers/weather.php | 2 +- p3k/Weather.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/weather.php b/controllers/weather.php index cb53298..7d1c377 100644 --- a/controllers/weather.php +++ b/controllers/weather.php @@ -16,7 +16,7 @@ $app->get('/api/weather', function() use($app) { } else { json_response($app, [ 'error' => 'not_found', - 'error_description' => 'No weather information was found for the requested location' + 'error_description' => 'No weather information was found for the requested location, or you used an invalid API key' ]); } } else { diff --git a/p3k/Weather.php b/p3k/Weather.php index c0cfc91..6fdef29 100644 --- a/p3k/Weather.php +++ b/p3k/Weather.php @@ -9,6 +9,9 @@ class Weather { $data = self::_fetch($lat, $lng, $key); if(!$data) return null; + if(!property_exists($data, 'current_observation')) + return null; + $current = $data->current_observation; $weather = [