forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaemonConnectionException.php
More file actions
45 lines (38 loc) · 1.31 KB
/
DaemonConnectionException.php
File metadata and controls
45 lines (38 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Pterodactyl\Exceptions\Http\Connection;
use Illuminate\Http\Response;
use GuzzleHttp\Exception\GuzzleException;
use Pterodactyl\Exceptions\DisplayException;
class DaemonConnectionException extends DisplayException
{
/**
* @var int
*/
private $statusCode = Response::HTTP_GATEWAY_TIMEOUT;
/**
* Throw a displayable exception caused by a daemon connection error.
*
* @param \GuzzleHttp\Exception\GuzzleException $previous
* @param bool $useStatusCode
*/
public function __construct(GuzzleException $previous, bool $useStatusCode = false)
{
/** @var \GuzzleHttp\Psr7\Response|null $response */
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
if ($useStatusCode) {
$this->statusCode = is_null($response) ? 500 : $response->getStatusCode();
}
parent::__construct(trans('admin/server.exceptions.daemon_exception', [
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
]), $previous, DisplayException::LEVEL_WARNING);
}
/**
* Return the HTTP status code for this exception.
*
* @return int
*/
public function getStatusCode()
{
return $this->statusCode;
}
}