Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Exception
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getCurlErrno
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRequest
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Http\Client\Handler;
16
17use Psr\Http\Client\NetworkExceptionInterface;
18use Psr\Http\Message\RequestInterface;
19
20/**
21 * HTTP client handler exception class
22 *
23 * @category   Pop
24 * @package    Pop\Http
25 * @author     Nick Sagona, III <nick@popphp.org>
26 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
27 * @license    https://www.popphp.org/license     New BSD License
28 * @version    6.0.0
29 */
30class Exception extends \Pop\Http\Client\Exception implements NetworkExceptionInterface
31{
32
33    /**
34     * The underlying curl error number, if this exception came from a curl failure
35     * @var int
36     */
37    protected int $curlErrno = 0;
38
39    /**
40     * The request in flight when the failure occurred, if the handler had been prepared
41     * @var ?RequestInterface
42     */
43    protected ?RequestInterface $request = null;
44
45    /**
46     * Constructor
47     *
48     * @param string             $message
49     * @param int                $code
50     * @param ?\Throwable        $previous
51     * @param int                $curlErrno
52     * @param ?RequestInterface  $request
53     */
54    public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null, int $curlErrno = 0, ?RequestInterface $request = null)
55    {
56        parent::__construct($message, $code, $previous);
57        $this->curlErrno = $curlErrno;
58        $this->request   = $request;
59    }
60
61    /**
62     * Get the underlying curl error number
63     *
64     * @return int
65     */
66    public function getCurlErrno(): int
67    {
68        return $this->curlErrno;
69    }
70
71    /**
72     * Get the request in flight when the failure occurred
73     *
74     * @throws \LogicException
75     * @return RequestInterface
76     */
77    public function getRequest(): RequestInterface
78    {
79        if ($this->request === null) {
80            throw new \LogicException('Error: No request is available for this exception - the handler was never prepared.');
81        }
82
83        return $this->request;
84    }
85
86}