mirror of
https://github.com/pelican-dev/panel.git
synced 2026-07-15 19:53:59 +03:00
restore daemon error surface for wings 4xx (#2325)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,9 +57,6 @@ abstract class DaemonRepository
|
||||
if (is_bool($condition)) {
|
||||
return $condition;
|
||||
}
|
||||
if ($condition->clientError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$header = $condition->header('User-Agent');
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user