1
0
mirror of https://koodu.h-i.works/projects/thebadspace synced 2025-05-06 14:41:02 -05:00

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.
This commit is contained in:
ro 2024-02-18 22:18:56 -06:00
parent e266df0a0f
commit 91297c809d

View File

@ -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();