Don't abort deleting a backup if the daemon cannot find it

This commit is contained in:
Dane Everitt 2020-05-09 19:19:45 -07:00
parent 52966ede89
commit d4e037db9c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 16 additions and 1 deletions

View file

@ -6,6 +6,9 @@ use Illuminate\Http\Response;
use GuzzleHttp\Exception\GuzzleException;
use Pterodactyl\Exceptions\DisplayException;
/**
* @method \GuzzleHttp\Exception\GuzzleException getPrevious()
*/
class DaemonConnectionException extends DisplayException
{
/**

View file

@ -2,10 +2,13 @@
namespace Pterodactyl\Services\Backups;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DeleteBackupService
{
@ -50,7 +53,16 @@ class DeleteBackupService
public function handle(Backup $backup)
{
$this->connection->transaction(function () use ($backup) {
$this->daemonBackupRepository->setServer($backup->server)->delete($backup);
try {
$this->daemonBackupRepository->setServer($backup->server)->delete($backup);
} catch (DaemonConnectionException $exception) {
$previous = $exception->getPrevious();
// Don't fail the request if the Daemon responds with a 404, just assume the backup
// doesn't actually exist and remove it's reference from the Panel as well.
if (! $previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exception;
}
}
$this->repository->delete($backup->id);
});