PHP 8.2.30
Preview: HttpException.php Size: 1.57 KB
/home/byroehnu/easetack.com/vendor/php-http/httplug/src/Exception/HttpException.php

<?php

namespace Http\Client\Exception;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * Thrown when a response was received but the request itself failed.
 *
 * In addition to the request, this exception always provides access to the response object.
 *
 * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
 */
class HttpException extends RequestException
{
    /**
     * @var ResponseInterface
     */
    protected $response;

    /**
     * @param string $message
     */
    public function __construct(
        $message,
        RequestInterface $request,
        ResponseInterface $response,
        ?\Exception $previous = null
    ) {
        parent::__construct($message, $request, $previous);

        $this->response = $response;
        $this->code = $response->getStatusCode();
    }

    /**
     * Returns the response.
     *
     * @return ResponseInterface
     */
    public function getResponse()
    {
        return $this->response;
    }

    /**
     * Factory method to create a new exception with a normalized error message.
     */
    public static function create(
        RequestInterface $request,
        ResponseInterface $response,
        ?\Exception $previous = null
    ) {
        $message = sprintf(
            '[url] %s [http method] %s [status code] %s [reason phrase] %s',
            $request->getRequestTarget(),
            $request->getMethod(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        );

        return new static($message, $request, $response, $previous);
    }
}

Directory Contents

Dirs: 0 × Files: 5

Name Size Perms Modified Actions
1.57 KB lrw-rw-rw- 2024-09-23 11:39:58
Edit Download
751 B lrw-rw-rw- 2024-09-23 11:39:58
Edit Download
378 B lrw-rw-rw- 2024-09-23 11:39:58
Edit Download
788 B lrw-rw-rw- 2024-09-23 11:39:58
Edit Download
263 B lrw-rw-rw- 2024-09-23 11:39:58
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).