Skip to content

Commit

Permalink
Failsafe for generic exceptions
Browse files Browse the repository at this point in the history
In case of bad/incompatible data in feed, this will be logged and processing will stop (with a result of `No NOTAM(s) found`)
  • Loading branch information
FatihKoz committed Jul 9, 2024
1 parent 90e471a commit 1b83ab1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Widgets/Notams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1b83ab1

Please sign in to comment.