Files
panel-pelican-dev/app/Exceptions/Http/Server/ServerStateConflictException.php

34 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Exceptions\Http\Server;
2024-04-18 03:50:20 -04:00
use App\Enums\ServerState;
2024-03-12 22:39:16 -04:00
use App\Models\Server;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
2025-09-24 13:34:19 +02:00
use Throwable;
class ServerStateConflictException extends ConflictHttpException
{
/**
* Exception thrown when the server is in an unsupported state for API access or
* certain operations within the codebase.
*/
public function __construct(Server $server, ?Throwable $previous = null)
{
$message = trans('exceptions.server.state_conflict');
if ($server->isSuspended()) {
$message = trans('exceptions.server.suspended');
} elseif ($server->node->isUnderMaintenance()) {
$message = trans('exceptions.server.maintenance');
} elseif (!$server->isInstalled()) {
$message = trans('exceptions.server.marked_as_failed');
2024-04-18 03:50:20 -04:00
} elseif ($server->status === ServerState::RestoringBackup) {
$message = trans('exceptions.server.restoring_backup');
} elseif (!is_null($server->transfer)) {
$message = trans('exceptions.server.transferring');
}
parent::__construct($message, $previous);
}
}