master

laravel/framework

Last updated at: 29/12/2023 09:24

HttpResponseException.php

TLDR

This file defines the HttpResponseException class, which extends the RuntimeException class. It is used to create a new exception instance specifically for HTTP responses.

Classes

HttpResponseException

This class extends the RuntimeException class and is used to create a new exception instance for HTTP responses. It has the following methods:

  • __construct(Response $response): This method is the constructor for the HttpResponseException class. It accepts a Symfony Response object as a parameter and assigns it to the $response property.
  • getResponse(): This method returns the underlying response instance assigned to the $response property.
<?php

namespace Illuminate\Http\Exceptions;

use RuntimeException;
use Symfony\Component\HttpFoundation\Response;

class HttpResponseException extends RuntimeException
{
    /**
     * The underlying response instance.
     *
     * @var \Symfony\Component\HttpFoundation\Response
     */
    protected $response;

    /**
     * Create a new HTTP response exception instance.
     *
     * @param  \Symfony\Component\HttpFoundation\Response  $response
     * @return void
     */
    public function __construct(Response $response)
    {
        $this->response = $response;
    }

    /**
     * Get the underlying response instance.
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function getResponse()
    {
        return $this->response;
    }
}