diff --git a/packages/realtime-compiler/src/Http/DashboardController.php b/packages/realtime-compiler/src/Http/DashboardController.php index 9c7279c134a..5afe1cb133c 100644 --- a/packages/realtime-compiler/src/Http/DashboardController.php +++ b/packages/realtime-compiler/src/Http/DashboardController.php @@ -71,7 +71,7 @@ public function __construct() throw $exception; } - $this->sendJsonResponse($exception); + $this->sendJsonErrorResponse($exception); } } } @@ -320,16 +320,30 @@ protected static function getPackageVersion(string $packageName): string return $prettyVersion ?? 'unreleased'; } - protected function sendJsonResponse(HttpException $exception): never + protected function sendJsonResponse(int $statusCode, string $body): never { - $statusMessage = match ($exception->getStatusCode()) { + $statusMessage = match ($statusCode) { 200 => 'OK', 201 => 'Created', + default => 'Internal Server Error', + }; + + (new JsonResponse($statusCode, $statusMessage, [ + 'body' => $body, + ]))->send(); + + exit; + } + + protected function sendJsonErrorResponse(HttpException $exception): never + { + $statusMessage = match ($exception->getStatusCode()) { 400 => 'Bad Request', 403 => 'Forbidden', 409 => 'Conflict', default => 'Internal Server Error', }; + (new JsonResponse($exception->getStatusCode(), $statusMessage, [ 'error' => $exception->getMessage(), ]))->send();