From 26901f82220fe18c0ad6e2bfc23c59b451a4e198 Mon Sep 17 00:00:00 2001 From: Frankie B <git@diskfloppy.me> Date: Fri, 8 Sep 2023 23:19:40 +0100 Subject: feat: add error handling (#14) * Remove commented out crap * Update theme to use some colors from catppuccin, add error handling for API/DB --- resources/views/pages/weather.blade.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'resources/views/pages/weather.blade.php') diff --git a/resources/views/pages/weather.blade.php b/resources/views/pages/weather.blade.php index 823c448..369927f 100644 --- a/resources/views/pages/weather.blade.php +++ b/resources/views/pages/weather.blade.php @@ -13,10 +13,22 @@ function degreesToCompassDirection($degrees) { return $cardinalDirections[round($degrees*16/360)]; } -$data = json_decode(file_get_contents($api_root.'/weather')); -$updated = gmdate('H:i Y-m-d', $data->updated); -$data = $data->current; +$api_alive = true; + +try { + $data = file_get_contents($api_root.'/weather'); +} catch (Exception $e) { + $api_alive = false; +} @endphp +@if (!$api_alive) + @include('components.errors.api-error') +@else + @php + $data = json_decode(file_get_contents($api_root.'/weather')); + $updated = gmdate('H:i Y-m-d', $data->updated); + $data = $data->current; + @endphp <table class="info-table"> <caption> <h1>Local Weather</h1> @@ -45,4 +57,5 @@ $data = $data->current; </table> <br> <small><i>(Last Update: {{ $updated }})</i></small> +@endif @stop -- cgit v1.2.3-54-g00ecf