PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / http / client / Exception / HttpException.php

HttpException.php in DecaLog 4.4.0, at includes/libraries/http/client/Exception/HttpException.php

66 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Http\Client\Exception;
4
5 use Psr\Http\Message\RequestInterface;
6 use Psr\Http\Message\ResponseInterface;
7
8 /**
9 * Thrown when a response was received but the request itself failed.
10 *
11 * In addition to the request, this exception always provides access to the response object.
12 *
13 * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
14 */
15 class HttpException extends RequestException
16 {
17 /**
18 * @var ResponseInterface
19 */
20 protected $response;
21
22 /**
23 * @param string $message
24 */
25 public function __construct(
26 $message,
27 RequestInterface $request,
28 ResponseInterface $response,
29 \Exception $previous = null
30 ) {
31 parent::__construct($message, $request, $previous);
32
33 $this->response = $response;
34 $this->code = $response->getStatusCode();
35 }
36
37 /**
38 * Returns the response.
39 *
40 * @return ResponseInterface
41 */
42 public function getResponse()
43 {
44 return $this->response;
45 }
46
47 /**
48 * Factory method to create a new exception with a normalized error message.
49 */
50 public static function create(
51 RequestInterface $request,
52 ResponseInterface $response,
53 \Exception $previous = null
54 ) {
55 $message = sprintf(
56 '[url] %s [http method] %s [status code] %s [reason phrase] %s',
57 $request->getRequestTarget(),
58 $request->getMethod(),
59 $response->getStatusCode(),
60 $response->getReasonPhrase()
61 );
62
63 return new static($message, $request, $response, $previous);
64 }
65 }
66