Network.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Errors; |
| 4 | |
| 5 | use WonderPush\Net\CurlHttpClient; |
| 6 | |
| 7 | if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access |
| 8 | |
| 9 | /** |
| 10 | * Network related errors, and API error responses. |
| 11 | */ |
| 12 | class Network extends Base { |
| 13 | |
| 14 | /** @var \WonderPush\Net\Request */ |
| 15 | protected $request; |
| 16 | |
| 17 | /** @var \WonderPush\Net\Response */ |
| 18 | protected $response; |
| 19 | |
| 20 | public function __construct(\WonderPush\Net\Request $request, \WonderPush\Net\Response $response) { |
| 21 | $msg = 'Network'; |
| 22 | if ($response && $response->getHeaders()) { |
| 23 | $headers = $response->getHeaders(); |
| 24 | $bits = array(); |
| 25 | $curlMessage = isset($headers[CurlHttpClient::HEADER_CURL_ERROR]) ? $headers[CurlHttpClient::HEADER_CURL_ERROR] : null; |
| 26 | if ($curlMessage) $bits []= $curlMessage; |
| 27 | $curlCode = isset($headers[CurlHttpClient::HEADER_CURL_ERRNO]) ? $headers[CurlHttpClient::HEADER_CURL_ERRNO] : null; |
| 28 | if ($curlCode) $bits []= "(" . $curlCode . ")"; |
| 29 | if (sizeof($bits)) $msg = join(' ', $bits); |
| 30 | } |
| 31 | parent::__construct($msg); |
| 32 | $this->request = $request; |
| 33 | $this->response = $response; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * The network request that was performed. |
| 38 | * @return \WonderPush\Net\Request |
| 39 | */ |
| 40 | public function getRequest() { |
| 41 | return $this->request; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * The network response that was received. |
| 46 | * @return \WonderPush\Net\Response |
| 47 | */ |
| 48 | public function getResponse() { |
| 49 | return $this->response; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 |