From 9c623eca71c4ffced83bdfd2d2590b1665d26258 Mon Sep 17 00:00:00 2001 From: Sky Mulley Date: Tue, 6 Oct 2026 02:10:17 +0100 Subject: [PATCH] port fix from 1.0 for display exceptions not returning correctly on api --- app/Exceptions/DisplayException.php | 2 +- .../Api/Application/Servers/ServerManagementTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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]);