From 1b83ab1200b09f67bbc19f10692ec4707ab746be Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" Date: Tue, 9 Jul 2024 22:33:55 +0300 Subject: [PATCH] Failsafe for generic exceptions In case of bad/incompatible data in feed, this will be logged and processing will stop (with a result of `No NOTAM(s) found`) --- Widgets/Notams.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Widgets/Notams.php b/Widgets/Notams.php index 3ff3c4e..8efeafe 100644 --- a/Widgets/Notams.php +++ b/Widgets/Notams.php @@ -4,6 +4,7 @@ use App\Contracts\Widget; use App\Models\Airport; +use Exception; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Support\Facades\Cache; @@ -43,12 +44,16 @@ public function run() Log::error('Disposable Basic | HTTP ' . $response->getStatusCode() . ' Error Occured During NOTAM Feed Retrieval !'); } } catch (GuzzleException $e) { - Log::error('Disposable Basic | NOTAM Feed Download Error, ' . $e->getMessage()); + Log::error('Disposable Basic | ' . $icao . ' NOTAM Feed Download Error, ' . $e->getMessage()); } - $rss_feed = isset($response) ? simplexml_load_string($response->getBody()) : null; + try { + $rss_feed = isset($response) ? simplexml_load_string($response->getBody()) : null; + } catch (Exception $e) { + Log::error('Disposable Basic | ' . $icao . ' NOTAM Feed Processing Error, ' . $e->getMessage()); + } - if ($rss_feed && is_object($rss_feed)) { + if (isset($rss_feed) && is_object($rss_feed)) { foreach ($rss_feed->channel->item as $notam) { if ($filter && !str_contains($notam->title, 'NOTAM A')) { continue;