From a46443e5e4baabd6a8744bdd340d428c24df6505 Mon Sep 17 00:00:00 2001 From: Noah Stefano Date: Tue, 9 Jun 2026 10:56:38 +0100 Subject: [PATCH] restore daemon error surface for wings 4xx (#2325) --- .../Daemon/DaemonFileRepository.php | 69 +++++++++++-------- app/Repositories/Daemon/DaemonRepository.php | 3 - 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/app/Repositories/Daemon/DaemonFileRepository.php b/app/Repositories/Daemon/DaemonFileRepository.php index 650d8447a..15e52fcdb 100644 --- a/app/Repositories/Daemon/DaemonFileRepository.php +++ b/app/Repositories/Daemon/DaemonFileRepository.php @@ -7,6 +7,7 @@ use App\Exceptions\Repository\FileExistsException; use App\Exceptions\Repository\FileNotEditableException; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Http\Client\ConnectionException; +use Illuminate\Http\Client\RequestException; use Illuminate\Http\Client\Response; class DaemonFileRepository extends DaemonRepository @@ -22,23 +23,29 @@ class DaemonFileRepository extends DaemonRepository */ public function getContent(string $path, ?int $notLargerThan = null): string { - $response = $this->getHttpClient()->get("/api/servers/{$this->server->uuid}/files/contents", - ['file' => $path] - ); + try { + $response = $this->getHttpClient()->get("/api/servers/{$this->server->uuid}/files/contents", + ['file' => $path] + ); + } catch (RequestException $exception) { + $status = $exception->response->status(); + + if ($status === 400) { + throw new FileNotEditableException(); + } + + if ($status === 404) { + throw new FileNotFoundException(); + } + + throw $exception; + } $length = $response->header('Content-Length'); if ($notLargerThan && $length > $notLargerThan) { throw new FileSizeTooLargeException(); } - if ($response->status() === 400) { - throw new FileNotEditableException(); - } - - if ($response->status() === 404) { - throw new FileNotFoundException(); - } - return $response; } @@ -51,16 +58,18 @@ class DaemonFileRepository extends DaemonRepository */ public function putContent(string $path, string $content): Response { - $response = $this->getHttpClient() - ->withQueryParameters(['file' => $path]) - ->withBody($content) - ->post("/api/servers/{$this->server->uuid}/files/write"); + try { + return $this->getHttpClient() + ->withQueryParameters(['file' => $path]) + ->withBody($content) + ->post("/api/servers/{$this->server->uuid}/files/write"); + } catch (RequestException $exception) { + if ($exception->response->status() === 400) { + throw new FileExistsException(); + } - if ($response->status() === 400) { - throw new FileExistsException(); + throw $exception; } - - return $response; } /** @@ -85,18 +94,20 @@ class DaemonFileRepository extends DaemonRepository */ public function createDirectory(string $name, string $path): Response { - $response = $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/files/create-directory", - [ - 'name' => $name, - 'path' => $path, - ] - ); + try { + return $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/files/create-directory", + [ + 'name' => $name, + 'path' => $path, + ] + ); + } catch (RequestException $exception) { + if ($exception->response->status() === 400) { + throw new FileExistsException(); + } - if ($response->status() === 400) { - throw new FileExistsException(); + throw $exception; } - - return $response; } /** diff --git a/app/Repositories/Daemon/DaemonRepository.php b/app/Repositories/Daemon/DaemonRepository.php index f8b85e0d1..18bfdbafe 100644 --- a/app/Repositories/Daemon/DaemonRepository.php +++ b/app/Repositories/Daemon/DaemonRepository.php @@ -57,9 +57,6 @@ abstract class DaemonRepository if (is_bool($condition)) { return $condition; } - if ($condition->clientError()) { - return false; - } $header = $condition->header('User-Agent'); if (