Always return the status code from the daemon if possible

This commit is contained in:
Dane Everitt 2020-07-18 10:23:28 -07:00
parent c2b1e7e6ab
commit d644758986
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 5 additions and 11 deletions

View File

@ -22,7 +22,7 @@ class DaemonConnectionException extends DisplayException
* @param \GuzzleHttp\Exception\GuzzleException $previous * @param \GuzzleHttp\Exception\GuzzleException $previous
* @param bool $useStatusCode * @param bool $useStatusCode
*/ */
public function __construct(GuzzleException $previous, bool $useStatusCode = false) public function __construct(GuzzleException $previous, bool $useStatusCode = true)
{ {
/** @var \GuzzleHttp\Psr7\Response|null $response */ /** @var \GuzzleHttp\Psr7\Response|null $response */
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null; $response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;

View File

@ -6,13 +6,11 @@ use Carbon\CarbonImmutable;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use GuzzleHttp\Exception\TransferException;
use Pterodactyl\Services\Nodes\NodeJWTService; use Pterodactyl\Services\Nodes\NodeJWTService;
use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Contracts\Routing\ResponseFactory;
use Pterodactyl\Repositories\Wings\DaemonFileRepository; use Pterodactyl\Repositories\Wings\DaemonFileRepository;
use Pterodactyl\Transformers\Daemon\FileObjectTransformer; use Pterodactyl\Transformers\Daemon\FileObjectTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest;
@ -70,13 +68,9 @@ class FileController extends ClientApiController
*/ */
public function directory(ListFilesRequest $request, Server $server): array public function directory(ListFilesRequest $request, Server $server): array
{ {
try { $contents = $this->fileRepository
$contents = $this->fileRepository ->setServer($server)
->setServer($server) ->getDirectory($request->get('directory') ?? '/');
->getDirectory($request->get('directory') ?? '/');
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception, true);
}
return $this->fractal->collection($contents) return $this->fractal->collection($contents)
->transformWith($this->getTransformer(FileObjectTransformer::class)) ->transformWith($this->getTransformer(FileObjectTransformer::class))

View File

@ -23,7 +23,7 @@ class DaemonServerRepository extends DaemonRepository
sprintf('/api/servers/%s', $this->server->uuid) sprintf('/api/servers/%s', $this->server->uuid)
); );
} catch (TransferException $exception) { } catch (TransferException $exception) {
throw new DaemonConnectionException($exception); throw new DaemonConnectionException($exception, false);
} }
return json_decode($response->getBody()->__toString(), true); return json_decode($response->getBody()->__toString(), true);