Handle any errors if unable to get presence or weather data

This commit is contained in:
floppydiskette 2024-08-31 00:47:01 +01:00
commit 29f40ced3b
4 changed files with 31 additions and 15 deletions

View file

@ -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 @@ public function getWeatherData(): mixed {
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;
}
}
/**