Catch correct Exceptions when updating/ deleting subusers (#828)

This commit is contained in:
Boy132 2024-12-12 17:32:39 +01:00 committed by GitHub
parent 663b097d22
commit 026494c353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 10 deletions

View File

@ -10,7 +10,6 @@ use Illuminate\Http\Client\RequestException;
use Webmozart\Assert\Assert;
use App\Models\Server;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\TransferException;
use App\Exceptions\Http\Connection\DaemonConnectionException;
class DaemonServerRepository extends DaemonRepository
@ -97,7 +96,7 @@ class DaemonServerRepository extends DaemonRepository
try {
$this->getHttpClient()->delete('/api/servers/' . $this->server->uuid);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
@ -116,7 +115,7 @@ class DaemonServerRepository extends DaemonRepository
'/api/servers/%s/reinstall',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
@ -136,7 +135,7 @@ class DaemonServerRepository extends DaemonRepository
'/api/servers/%s/archive',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
@ -159,7 +158,7 @@ class DaemonServerRepository extends DaemonRepository
'/api/servers/%s/transfer',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
@ -175,7 +174,7 @@ class DaemonServerRepository extends DaemonRepository
],
],
]);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
@ -210,7 +209,7 @@ class DaemonServerRepository extends DaemonRepository
->post(sprintf('/api/servers/%s/ws/deny', $this->server->uuid), [
'jtis' => $jtis,
]);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}

View File

@ -8,6 +8,7 @@ use Illuminate\Database\ConnectionInterface;
use App\Traits\Services\ReturnsUpdatedModels;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;
class DetailsModificationService
{
@ -41,7 +42,7 @@ class DetailsModificationService
if ($server->owner_id !== $owner) {
try {
$this->serverRepository->setServer($server)->revokeUserJTI($owner);
} catch (DaemonConnectionException $exception) {
} catch (ConnectionException|DaemonConnectionException) {
// Do nothing. A failure here is not ideal, but it is likely to be caused by daemon
// being offline, or in an entirely broken state. Remember, these tokens reset every
// few minutes by default, we're just trying to help it along a little quicker.

View File

@ -8,6 +8,7 @@ use App\Facades\Activity;
use App\Models\Server;
use App\Models\Subuser;
use App\Repositories\Daemon\DaemonServerRepository;
use Illuminate\Http\Client\ConnectionException;
class SubuserDeletionService
{
@ -29,7 +30,7 @@ class SubuserDeletionService
try {
$this->serverRepository->setServer($server)->revokeUserJTI($subuser->user_id);
} catch (DaemonConnectionException $exception) {
} catch (ConnectionException|DaemonConnectionException $exception) {
// Don't block this request if we can't connect to the daemon instance.
logger()->warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]);

View File

@ -7,6 +7,7 @@ use App\Facades\Activity;
use App\Models\Server;
use App\Models\Subuser;
use App\Repositories\Daemon\DaemonServerRepository;
use Illuminate\Http\Client\ConnectionException;
class SubuserUpdateService
{
@ -38,7 +39,7 @@ class SubuserUpdateService
try {
$this->serverRepository->setServer($server)->revokeUserJTI($subuser->user_id);
} catch (DaemonConnectionException $exception) {
} catch (ConnectionException|DaemonConnectionException $exception) {
// Don't block this request if we can't connect to the daemon instance. Chances are it is
// offline and the token will be invalid once daemon boots back.
logger()->warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]);