diff --git a/app/Exceptions/DisplayException.php b/app/Exceptions/DisplayException.php index a34ad9c1b..91c4deeb5 100644 --- a/app/Exceptions/DisplayException.php +++ b/app/Exceptions/DisplayException.php @@ -57,7 +57,7 @@ class DisplayException extends PterodactylException implements HttpExceptionInte */ public function render(Request $request): JsonResponse|RedirectResponse { - if ($request->expectsJson()) { + if ($request->expectsJson() || $request->is('api/*')) { return response()->json(ApiErrorResponse::toArray($this), $this->getStatusCode(), $this->getHeaders()); } diff --git a/tests/Integration/Api/Application/Servers/ServerManagementTest.php b/tests/Integration/Api/Application/Servers/ServerManagementTest.php index a4f492cc3..d42a73da9 100644 --- a/tests/Integration/Api/Application/Servers/ServerManagementTest.php +++ b/tests/Integration/Api/Application/Servers/ServerManagementTest.php @@ -87,6 +87,16 @@ test('a server that skips its install script cannot be reinstalled', function () expect($server->refresh()->status)->toBeNull() ->and($fake->callsFor('reinstall'))->toBeEmpty(); }); +test('a blocked reinstall returns an error to clients not requesting json', function (): void { + $fake = new FakeDaemonServer; + $server = $this->createServerModel(['skip_scripts' => true]); + + $this->post("/api/application/servers/{$server->id}/reinstall", [], ['Accept' => '*/*']) + ->assertStatus(Response::HTTP_BAD_REQUEST) + ->assertJsonPath('errors.0.detail', trans('admin/server.exceptions.skipping_install_script')); + + expect($fake->callsFor('reinstall'))->toBeEmpty(); +}); test('a server that skips its install script can be reinstalled from an unfinished install', function (string $status): void { $fake = new FakeDaemonServer; $server = $this->createServerModel(['skip_scripts' => true, 'status' => $status]);