diff options
author | floppydiskette <floppydisk@hyprcat.net> | 2024-08-31 00:47:01 +0100 |
---|---|---|
committer | floppydiskette <floppydisk@hyprcat.net> | 2024-08-31 00:47:01 +0100 |
commit | a715ae58afa15a98006e2271522bef5a00ca071f (patch) | |
tree | 5e64ac5ac9e30fd14b96f8e88d3f449fda223ac1 /app/View/Components/Weather.php | |
parent | 97d8f4447d0839d3f251a7dfc2f5f123c36c4d5e (diff) |
Handle any errors if unable to get presence or weather data
Diffstat (limited to 'app/View/Components/Weather.php')
-rw-r--r-- | app/View/Components/Weather.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/app/View/Components/Weather.php b/app/View/Components/Weather.php index 69be9fd..dcf3ff7 100644 --- a/app/View/Components/Weather.php +++ b/app/View/Components/Weather.php @@ -3,6 +3,7 @@ namespace App\View\Components; use Closure; +use Exception; use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Config; @@ -25,11 +26,16 @@ class Weather extends Component return Cache::get('weather_data'); } - $response = Http::get('http://'. Config::get('services.weatherlink') . '/v1/current_conditions'); - $data = $response->json(); - $conditions = $data["data"]["conditions"]; - Cache::put('weather_data', $conditions, now()->addSeconds(60)); - return $conditions; + try { + $response = Http::get('http://' . Config::get('services.weatherlink') . '/v1/current_conditions'); + $data = $response->json(); + $conditions = $data["data"]["conditions"]; + Cache::put('weather_data', $conditions, now()->addSeconds(60)); + return $conditions; + } catch (Exception $ex) { + return null; + } + } /** |