Skip to content

Commit

Permalink
Catch correct Exceptions when updating/ deleting subusers (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 authored Dec 12, 2024
1 parent 663b097 commit 026494c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
13 changes: 6 additions & 7 deletions app/Repositories/Daemon/DaemonServerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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
Expand Down Expand Up @@ -97,7 +96,7 @@ public function delete(): void

try {
$this->getHttpClient()->delete('/api/servers/' . $this->server->uuid);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
Expand All @@ -116,7 +115,7 @@ public function reinstall(): void
'/api/servers/%s/reinstall',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
Expand All @@ -136,7 +135,7 @@ public function requestArchive(): void
'/api/servers/%s/archive',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
Expand All @@ -159,7 +158,7 @@ public function cancelTransfer(): void
'/api/servers/%s/transfer',
$this->server->uuid
));
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}

Expand All @@ -175,7 +174,7 @@ public function cancelTransfer(): void
],
],
]);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
Expand Down Expand Up @@ -210,7 +209,7 @@ protected function revokeJTIs(array $jtis): void
->post(sprintf('/api/servers/%s/ws/deny', $this->server->uuid), [
'jtis' => $jtis,
]);
} catch (TransferException $exception) {
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Servers/DetailsModificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Traits\Services\ReturnsUpdatedModels;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;

class DetailsModificationService
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public function handle(Server $server, array $data): Server
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.
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Subusers/SubuserDeletionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Server;
use App\Models\Subuser;
use App\Repositories\Daemon\DaemonServerRepository;
use Illuminate\Http\Client\ConnectionException;

class SubuserDeletionService
{
Expand All @@ -29,7 +30,7 @@ public function handle(Subuser $subuser, Server $server): void

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]);

Expand Down
3 changes: 2 additions & 1 deletion app/Services/Subusers/SubuserUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Server;
use App\Models\Subuser;
use App\Repositories\Daemon\DaemonServerRepository;
use Illuminate\Http\Client\ConnectionException;

class SubuserUpdateService
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public function handle(Subuser $subuser, Server $server, array $permissions): vo

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]);
Expand Down

0 comments on commit 026494c

Please sign in to comment.