22
33namespace Pterodactyl \Exceptions \Http \Connection ;
44
5+ use Illuminate \Support \Arr ;
56use Illuminate \Http \Response ;
67use GuzzleHttp \Exception \GuzzleException ;
78use 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