2017-10-06 05:16:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Exceptions\Http\Connection;
|
|
|
|
|
2018-01-31 02:36:59 +00:00
|
|
|
use Illuminate\Http\Response;
|
2017-10-06 05:16:22 +00:00
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
|
|
|
|
class DaemonConnectionException extends DisplayException
|
|
|
|
{
|
2017-12-31 16:30:19 +00:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
2018-01-31 02:36:59 +00:00
|
|
|
private $statusCode = Response::HTTP_GATEWAY_TIMEOUT;
|
2017-12-31 16:30:19 +00:00
|
|
|
|
2017-10-06 05:16:22 +00:00
|
|
|
/**
|
|
|
|
* Throw a displayable exception caused by a daemon connection error.
|
|
|
|
*
|
|
|
|
* @param \GuzzleHttp\Exception\GuzzleException $previous
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param bool $useStatusCode
|
2017-10-06 05:16:22 +00:00
|
|
|
*/
|
2017-12-31 16:30:19 +00:00
|
|
|
public function __construct(GuzzleException $previous, bool $useStatusCode = false)
|
2017-10-06 05:16:22 +00:00
|
|
|
{
|
|
|
|
/** @var \GuzzleHttp\Psr7\Response|null $response */
|
|
|
|
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
|
|
|
|
|
2017-12-31 16:30:19 +00:00
|
|
|
if ($useStatusCode) {
|
|
|
|
$this->statusCode = is_null($response) ? 500 : $response->getStatusCode();
|
|
|
|
}
|
|
|
|
|
2017-10-06 05:16:22 +00:00
|
|
|
parent::__construct(trans('admin/server.exceptions.daemon_exception', [
|
|
|
|
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
|
|
|
]), $previous, DisplayException::LEVEL_WARNING);
|
|
|
|
}
|
2017-12-31 16:30:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the HTTP status code for this exception.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getStatusCode()
|
|
|
|
{
|
|
|
|
return $this->statusCode;
|
|
|
|
}
|
2017-10-06 05:16:22 +00:00
|
|
|
}
|