Skip to content

Commit 800b475

Browse files
committed
Respond with the actual error from wings if available; closes pterodactyl#2224
1 parent 231ff03 commit 800b475

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

app/Exceptions/Http/Connection/DaemonConnectionException.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Exceptions\Http\Connection;
44

5+
use Illuminate\Support\Arr;
56
use Illuminate\Http\Response;
67
use GuzzleHttp\Exception\GuzzleException;
78
use Pterodactyl\Exceptions\DisplayException;
@@ -28,12 +29,28 @@ public function __construct(GuzzleException $previous, bool $useStatusCode = tru
2829
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
2930

3031
if ($useStatusCode) {
31-
$this->statusCode = is_null($response) ? 500 : $response->getStatusCode();
32+
$this->statusCode = is_null($response) ? $this->statusCode : $response->getStatusCode();
3233
}
3334

34-
parent::__construct(trans('admin/server.exceptions.daemon_exception', [
35+
$message = trans('admin/server.exceptions.daemon_exception', [
3536
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
36-
]), $previous, DisplayException::LEVEL_WARNING);
37+
]);
38+
39+
// Attempt to pull the actual error message off the response and return that if it is not
40+
// a 500 level error.
41+
if ($this->statusCode < 500 && ! is_null($response)) {
42+
$body = $response->getBody();
43+
if (is_string($body) || (is_object($body) && method_exists($body, '__toString'))) {
44+
$body = json_decode(is_string($body) ? $body : $body->__toString(), true);
45+
$message = "[Wings Error]: " . Arr::get($body, 'error', $message);
46+
}
47+
}
48+
49+
$level = $this->statusCode >= 500 && $this->statusCode !== 504
50+
? DisplayException::LEVEL_ERROR
51+
: DisplayException::LEVEL_WARNING;
52+
53+
parent::__construct($message, $previous, $level);
3754
}
3855

3956
/**

0 commit comments

Comments
 (0)