port fix from 1.0 for display exceptions not returning correctly on api

This commit is contained in:
Sky Mulley
2026-10-06 02:10:17 +01:00
parent 90fc8c7005
commit 9c623eca71
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -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());
}
@@ -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]);