2021-01-30 13:28:31 -08:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Exceptions\Http\Server;
|
2021-01-30 13:28:31 -08:00
|
|
|
|
2024-04-18 03:50:20 -04:00
|
|
|
use App\Enums\ServerState;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Models\Server;
|
2021-01-30 13:28:31 -08:00
|
|
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
2025-09-24 13:34:19 +02:00
|
|
|
use Throwable;
|
2021-01-30 13:28:31 -08:00
|
|
|
|
|
|
|
|
class ServerStateConflictException extends ConflictHttpException
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Exception thrown when the server is in an unsupported state for API access or
|
|
|
|
|
* certain operations within the codebase.
|
|
|
|
|
*/
|
2025-09-08 13:12:33 -04:00
|
|
|
public function __construct(Server $server, ?Throwable $previous = null)
|
2021-01-30 13:28:31 -08:00
|
|
|
{
|
|
|
|
|
$message = 'This server is currently in an unsupported state, please try again later.';
|
|
|
|
|
if ($server->isSuspended()) {
|
|
|
|
|
$message = 'This server is currently suspended and the functionality requested is unavailable.';
|
2022-11-07 00:02:30 +01:00
|
|
|
} elseif ($server->node->isUnderMaintenance()) {
|
|
|
|
|
$message = 'The node of this server is currently under maintenance and the functionality requested is unavailable.';
|
2021-01-30 13:28:31 -08:00
|
|
|
} elseif (!$server->isInstalled()) {
|
|
|
|
|
$message = 'This server has not yet completed its installation process, please try again later.';
|
2024-04-18 03:50:20 -04:00
|
|
|
} elseif ($server->status === ServerState::RestoringBackup) {
|
2021-01-30 13:28:31 -08:00
|
|
|
$message = 'This server is currently restoring from a backup, please try again later.';
|
|
|
|
|
} elseif (!is_null($server->transfer)) {
|
|
|
|
|
$message = 'This server is currently being transferred to a new machine, please try again later.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::__construct($message, $previous);
|
|
|
|
|
}
|
|
|
|
|
}
|