Skip to content

Commit d4e037d

Browse files
committed
Don't abort deleting a backup if the daemon cannot find it
1 parent 52966ed commit d4e037d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/Exceptions/Http/Connection/DaemonConnectionException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use GuzzleHttp\Exception\GuzzleException;
77
use Pterodactyl\Exceptions\DisplayException;
88

9+
/**
10+
* @method \GuzzleHttp\Exception\GuzzleException getPrevious()
11+
*/
912
class DaemonConnectionException extends DisplayException
1013
{
1114
/**

app/Services/Backups/DeleteBackupService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Pterodactyl\Services\Backups;
44

5+
use Illuminate\Http\Response;
56
use Pterodactyl\Models\Backup;
7+
use GuzzleHttp\Exception\ClientException;
68
use Illuminate\Database\ConnectionInterface;
79
use Pterodactyl\Repositories\Eloquent\BackupRepository;
810
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
11+
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
912

1013
class DeleteBackupService
1114
{
@@ -50,7 +53,16 @@ public function __construct(
5053
public function handle(Backup $backup)
5154
{
5255
$this->connection->transaction(function () use ($backup) {
53-
$this->daemonBackupRepository->setServer($backup->server)->delete($backup);
56+
try {
57+
$this->daemonBackupRepository->setServer($backup->server)->delete($backup);
58+
} catch (DaemonConnectionException $exception) {
59+
$previous = $exception->getPrevious();
60+
// Don't fail the request if the Daemon responds with a 404, just assume the backup
61+
// doesn't actually exist and remove it's reference from the Panel as well.
62+
if (! $previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
63+
throw $exception;
64+
}
65+
}
5466

5567
$this->repository->delete($backup->id);
5668
});

0 commit comments

Comments
 (0)