From 3edd6e552153a3b3f8df67be18556e5b58e0d194 Mon Sep 17 00:00:00 2001 From: ro Date: Sun, 18 Feb 2024 22:18:56 -0600 Subject: [PATCH] Update script error handling finally found the correct exception that captures a connect error when a source url cannot be loaded, so it logs the error and just keep executing the script. Now automation can be enabled since the system knows how to handle errors. Fuck. Yes. --- app/Services/UpdateService.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app/Services/UpdateService.php b/app/Services/UpdateService.php index 3b8ce34..335c827 100644 --- a/app/Services/UpdateService.php +++ b/app/Services/UpdateService.php @@ -7,6 +7,7 @@ use App\Repositories\LocationRepository; use App\Models\Source; use Ramsey\Uuid\Uuid; use Carbon\Carbon; +use GuzzleHttp\Exception\ConnectException; class UpdateService { @@ -26,18 +27,27 @@ class UpdateService $checked = []; //checks source url to make sure they valid foreach ($sources as $source) { - if ($this->urlExists('https://' . $source->url)) { - $result = []; - if ($source['type'] == 'mastodon') { - if ($source['token'] == null) { + $result = []; + if ($source['type'] == 'mastodon') { + if ($source['token'] == null) { + try { $result = \Mastodon::domain('https://' . $source['url']) ->get('/instance/domain_blocks'); - } else { + array_push($checked, ['source' => $source->url]); + } catch (ConnectException $e) { + array_push($missing, ['source' => $source->url]); + } + } else { + try { $result = \Mastodon::domain('https://' . $source['url']) ->token($source['token']) ->get('/instance/domain_blocks'); + array_push($checked, ['source' => $source->url]); + } catch (ConnectException $e) { } - } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + } + } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + try { $denylist = array_map('str_getcsv', file('https://' . $source['url'])); foreach ($denylist as $item) { array_push($result, [ @@ -45,11 +55,12 @@ class UpdateService 'severity' => $item[1], 'comment' => $item[2]]); } + array_push($checked, ['source' => $source->url]); + } catch (Exception $e) { + array_push($missing, ['source' => $source->url]); } - array_push($checked, ['source' => $source->url]); - } else { - array_push($missing, ['source' => $source->url]); - }; + } + $source->list_data = json_encode($result); $source->last_updated = Carbon::now(); $source->save();