forked from projects/thebadspace
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:
parent
7abd6d44a0
commit
3edd6e5521
1 changed files with 21 additions and 10 deletions
|
@ -7,6 +7,7 @@ use App\Repositories\LocationRepository;
|
||||||
use App\Models\Source;
|
use App\Models\Source;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
|
|
||||||
class UpdateService
|
class UpdateService
|
||||||
{
|
{
|
||||||
|
@ -26,18 +27,27 @@ class UpdateService
|
||||||
$checked = [];
|
$checked = [];
|
||||||
//checks source url to make sure they valid
|
//checks source url to make sure they valid
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
if ($this->urlExists('https://' . $source->url)) {
|
|
||||||
$result = [];
|
$result = [];
|
||||||
if ($source['type'] == 'mastodon') {
|
if ($source['type'] == 'mastodon') {
|
||||||
if ($source['token'] == null) {
|
if ($source['token'] == null) {
|
||||||
|
try {
|
||||||
$result = \Mastodon::domain('https://' . $source['url'])
|
$result = \Mastodon::domain('https://' . $source['url'])
|
||||||
->get('/instance/domain_blocks');
|
->get('/instance/domain_blocks');
|
||||||
|
array_push($checked, ['source' => $source->url]);
|
||||||
|
} catch (ConnectException $e) {
|
||||||
|
array_push($missing, ['source' => $source->url]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
$result = \Mastodon::domain('https://' . $source['url'])
|
$result = \Mastodon::domain('https://' . $source['url'])
|
||||||
->token($source['token'])
|
->token($source['token'])
|
||||||
->get('/instance/domain_blocks');
|
->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']));
|
$denylist = array_map('str_getcsv', file('https://' . $source['url']));
|
||||||
foreach ($denylist as $item) {
|
foreach ($denylist as $item) {
|
||||||
array_push($result, [
|
array_push($result, [
|
||||||
|
@ -45,11 +55,12 @@ class UpdateService
|
||||||
'severity' => $item[1],
|
'severity' => $item[1],
|
||||||
'comment' => $item[2]]);
|
'comment' => $item[2]]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
array_push($checked, ['source' => $source->url]);
|
array_push($checked, ['source' => $source->url]);
|
||||||
} else {
|
} catch (Exception $e) {
|
||||||
array_push($missing, ['source' => $source->url]);
|
array_push($missing, ['source' => $source->url]);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$source->list_data = json_encode($result);
|
$source->list_data = json_encode($result);
|
||||||
$source->last_updated = Carbon::now();
|
$source->last_updated = Carbon::now();
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
Loading…
Reference in a new issue