class Handler implements ExceptionHandler (View source)

Traits

Properties

protected Container $container

The container implementation.

protected Throwable>> $dontReport

A list of the exception types that are not reported.

protected ReportableHandler[] $reportCallbacks

The callbacks that should be used during reporting.

protected $levels

A map of exceptions with their corresponding custom log levels.

protected array $throttleCallbacks

The callbacks that should be used to throttle reportable exceptions.

protected array $contextCallbacks

The callbacks that should be used to build exception context data.

protected Closure[] $renderCallbacks

The callbacks that should be used during rendering.

protected callable|null $shouldRenderJsonWhenCallback

The callback that determines if the exception handler response should be JSON.

protected callable|null $finalizeResponseCallback

The callback that prepares responses to be returned to the browser.

protected Closure> $exceptionMap

The registered exception mappings.

protected bool $hashThrottleKeys

Indicates that throttled keys should be hashed.

protected Throwable>> $internalDontReport

A list of the internal exception types that should not be reported.

protected array<int,string> $dontFlash

A list of the inputs that are never flashed for validation exceptions.

protected bool $withoutDuplicates

Indicates that an exception instance should only be reported once.

protected WeakMap $reportedExceptionMap

The already reported exception map.

Methods

string
firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

array
firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

array
closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

void
__construct(Container $container)

Create a new exception handler instance.

void
register()

Register the exception handling callbacks for the application.

reportable(callable $reportUsing)

Register a reportable callback.

$this
renderable(callable $renderUsing)

Register a renderable callback.

$this
map(Closure|string $from, Closure|string|null $to = null)

Register a new exception mapping.

$this
dontReport(array|string $exceptions)

Indicate that the given exception type should not be reported.

$this
ignore(array|string $exceptions)

Indicate that the given exception type should not be reported.

$this
dontFlash(array|string $attributes)

Indicate that the given attributes should never be flashed to the session on validation errors.

$this
level(Throwable> $type, $level)

Set the log level for the given exception type.

void
report(Throwable $e)

Report or log an exception.

void
reportThrowable(Throwable $e)

Reports error based on report method on exception or to logger.

bool
shouldReport(Throwable $e)

Determine if the exception should be reported.

bool
shouldntReport(Throwable $e)

Determine if the exception is in the "do not report" list.

Lottery|Limit|null
throttle(Throwable $e)

Throttle the given exception.

$this
throttleUsing(callable $throttleUsing)

Specify the callback that should be used to throttle reportable exceptions.

$this
stopIgnoring(array|string $exceptions)

Remove the given exception class from the list of exceptions that should be ignored.

array
buildExceptionContext(Throwable $e)

Create the context array for logging the given exception.

array
exceptionContext(Throwable $e)

Get the default exception context variables for logging.

array
context()

Get the default context variables for logging.

$this
buildContextUsing(Closure $contextCallback)

Register a closure that should be used to build exception context data.

Response
render(Request $request, Throwable $e)

Render an exception into an HTTP response.

Response
finalizeRenderedResponse(Request $request, Response $response, Throwable $e)

Prepare the final, rendered response to be returned to the browser.

$this
respondUsing(callable $callback)

Prepare the final, rendered response for an exception using the given callback.

prepareException(Throwable $e)

Prepare exception for rendering.

mapException(Throwable $e)

Map the exception using a registered mapper if possible.

mixed
renderViaCallbacks(Request $request, Throwable $e)

Try to render a response from request and exception via render callbacks.

renderExceptionResponse(Request $request, Throwable $e)

Render a default exception response if any.

unauthenticated(Request $request, AuthenticationException $exception)

Convert an authentication exception into a response.

Response
convertValidationExceptionToResponse(ValidationException $e, Request $request)

Create a response object from the given validation exception.

invalid(Request $request, ValidationException $exception)

Convert a validation exception into a response.

invalidJson(Request $request, ValidationException $exception)

Convert a validation exception into a JSON response.

bool
shouldReturnJson(Request $request, Throwable $e)

Determine if the exception handler response should be JSON.

$this
shouldRenderJsonWhen($callback)

Register the callable that determines if the exception handler response should be JSON.

prepareResponse(Request $request, Throwable $e)

Prepare a response for the given exception.

Response
convertExceptionToResponse(Throwable $e)

Create a Symfony response for the given exception.

string
renderExceptionContent(Throwable $e)

Get the response content for the given exception.

string
renderExceptionWithCustomRenderer(Throwable $e)

Render an exception to a string using the registered ExceptionRenderer.

string
renderExceptionWithSymfony(Throwable $e, bool $debug)

Render an exception to a string using Symfony.

Response
renderHttpException(HttpExceptionInterface $e)

Render the given HttpException.

void
registerErrorViewPaths()

Register the error template hint paths.

string|null
getHttpExceptionView(HttpExceptionInterface $e)

Get the view used to render HTTP exceptions.

toIlluminateResponse(Response $response, Throwable $e)

Map the given exception into an Illuminate response.

prepareJsonResponse(Request $request, Throwable $e)

Prepare a JSON response for the given exception.

array
convertExceptionToArray(Throwable $e)

Convert the given exception to an array.

void
renderForConsole(OutputInterface $output, Throwable $e)

Render an exception to the console.

$this
dontReportDuplicates()

Do not report duplicate exceptions.

bool
isHttpException(Throwable $e)

Determine if the given exception is an HTTP exception.

mapLogLevel(Throwable $e)

Map the exception to a log level.

LoggerInterface
newLogger()

Create a new logger instance.

Details

protected string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

Parameters

Closure $closure

Return Value

string

Exceptions

ReflectionException
RuntimeException

protected array firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException
RuntimeException

protected array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

void __construct(Container $container)

Create a new exception handler instance.

Parameters

Container $container

Return Value

void

void register()

Register the exception handling callbacks for the application.

Return Value

void

ReportableHandler reportable(callable $reportUsing)

Register a reportable callback.

Parameters

callable $reportUsing

Return Value

ReportableHandler

$this renderable(callable $renderUsing)

Register a renderable callback.

Parameters

callable $renderUsing

Return Value

$this

$this map(Closure|string $from, Closure|string|null $to = null)

Register a new exception mapping.

Parameters

Closure|string $from
Closure|string|null $to

Return Value

$this

Exceptions

InvalidArgumentException

$this dontReport(array|string $exceptions)

Indicate that the given exception type should not be reported.

Alias of "ignore".

Parameters

array|string $exceptions

Return Value

$this

$this ignore(array|string $exceptions)

Indicate that the given exception type should not be reported.

Parameters

array|string $exceptions

Return Value

$this

$this dontFlash(array|string $attributes)

Indicate that the given attributes should never be flashed to the session on validation errors.

Parameters

array|string $attributes

Return Value

$this

$this level(Throwable> $type, $level)

Set the log level for the given exception type.

Parameters

Throwable> $type
$level

Return Value

$this

void report(Throwable $e)

Report or log an exception.

Parameters

Throwable $e

Return Value

void

Exceptions

Throwable

protected void reportThrowable(Throwable $e)

Reports error based on report method on exception or to logger.

Parameters

Throwable $e

Return Value

void

Exceptions

Throwable

bool shouldReport(Throwable $e)

Determine if the exception should be reported.

Parameters

Throwable $e

Return Value

bool

protected bool shouldntReport(Throwable $e)

Determine if the exception is in the "do not report" list.

Parameters

Throwable $e

Return Value

bool

protected Lottery|Limit|null throttle(Throwable $e)

Throttle the given exception.

Parameters

Throwable $e

Return Value

Lottery|Limit|null

$this throttleUsing(callable $throttleUsing)

Specify the callback that should be used to throttle reportable exceptions.

Parameters

callable $throttleUsing

Return Value

$this

$this stopIgnoring(array|string $exceptions)

Remove the given exception class from the list of exceptions that should be ignored.

Parameters

array|string $exceptions

Return Value

$this

protected array buildExceptionContext(Throwable $e)

Create the context array for logging the given exception.

Parameters

Throwable $e

Return Value

array

protected array exceptionContext(Throwable $e)

Get the default exception context variables for logging.

Parameters

Throwable $e

Return Value

array

protected array context()

Get the default context variables for logging.

Return Value

array

$this buildContextUsing(Closure $contextCallback)

Register a closure that should be used to build exception context data.

Parameters

Closure $contextCallback

Return Value

$this

Response render(Request $request, Throwable $e)

Render an exception into an HTTP response.

Parameters

Request $request
Throwable $e

Return Value

Response

Exceptions

Throwable

protected Response finalizeRenderedResponse(Request $request, Response $response, Throwable $e)

Prepare the final, rendered response to be returned to the browser.

Parameters

Request $request
Response $response
Throwable $e

Return Value

Response

$this respondUsing(callable $callback)

Prepare the final, rendered response for an exception using the given callback.

Parameters

callable $callback

Return Value

$this

protected Throwable prepareException(Throwable $e)

Prepare exception for rendering.

Parameters

Throwable $e

Return Value

Throwable

protected Throwable mapException(Throwable $e)

Map the exception using a registered mapper if possible.

Parameters

Throwable $e

Return Value

Throwable

protected mixed renderViaCallbacks(Request $request, Throwable $e)

Try to render a response from request and exception via render callbacks.

Parameters

Request $request
Throwable $e

Return Value

mixed

Exceptions

ReflectionException

protected Response|JsonResponse|RedirectResponse renderExceptionResponse(Request $request, Throwable $e)

Render a default exception response if any.

Parameters

Request $request
Throwable $e

Return Value

Response|JsonResponse|RedirectResponse

protected Response|JsonResponse|RedirectResponse unauthenticated(Request $request, AuthenticationException $exception)

Convert an authentication exception into a response.

Parameters

Request $request
AuthenticationException $exception

Return Value

Response|JsonResponse|RedirectResponse

protected Response convertValidationExceptionToResponse(ValidationException $e, Request $request)

Create a response object from the given validation exception.

Parameters

ValidationException $e
Request $request

Return Value

Response

protected Response|JsonResponse|RedirectResponse invalid(Request $request, ValidationException $exception)

Convert a validation exception into a response.

Parameters

Request $request
ValidationException $exception

Return Value

Response|JsonResponse|RedirectResponse

protected JsonResponse invalidJson(Request $request, ValidationException $exception)

Convert a validation exception into a JSON response.

Parameters

Request $request
ValidationException $exception

Return Value

JsonResponse

protected bool shouldReturnJson(Request $request, Throwable $e)

Determine if the exception handler response should be JSON.

Parameters

Request $request
Throwable $e

Return Value

bool

$this shouldRenderJsonWhen($callback)

Register the callable that determines if the exception handler response should be JSON.

Parameters

$callback

Return Value

$this

protected Response|JsonResponse|RedirectResponse prepareResponse(Request $request, Throwable $e)

Prepare a response for the given exception.

Parameters

Request $request
Throwable $e

Return Value

Response|JsonResponse|RedirectResponse

protected Response convertExceptionToResponse(Throwable $e)

Create a Symfony response for the given exception.

Parameters

Throwable $e

Return Value

Response

protected string renderExceptionContent(Throwable $e)

Get the response content for the given exception.

Parameters

Throwable $e

Return Value

string

protected string renderExceptionWithCustomRenderer(Throwable $e)

Render an exception to a string using the registered ExceptionRenderer.

Parameters

Throwable $e

Return Value

string

protected string renderExceptionWithSymfony(Throwable $e, bool $debug)

Render an exception to a string using Symfony.

Parameters

Throwable $e
bool $debug

Return Value

string

protected Response renderHttpException(HttpExceptionInterface $e)

Render the given HttpException.

Parameters

HttpExceptionInterface $e

Return Value

Response

protected void registerErrorViewPaths()

Register the error template hint paths.

Return Value

void

protected string|null getHttpExceptionView(HttpExceptionInterface $e)

Get the view used to render HTTP exceptions.

Parameters

HttpExceptionInterface $e

Return Value

string|null

protected Response|RedirectResponse toIlluminateResponse(Response $response, Throwable $e)

Map the given exception into an Illuminate response.

Parameters

Response $response
Throwable $e

Return Value

Response|RedirectResponse

protected JsonResponse prepareJsonResponse(Request $request, Throwable $e)

Prepare a JSON response for the given exception.

Parameters

Request $request
Throwable $e

Return Value

JsonResponse

protected array convertExceptionToArray(Throwable $e)

Convert the given exception to an array.

Parameters

Throwable $e

Return Value

array

void renderForConsole(OutputInterface $output, Throwable $e)

internal  This method is not meant to be used or overwritten outside the framework.
 

Render an exception to the console.

Parameters

OutputInterface $output
Throwable $e

Return Value

void

$this dontReportDuplicates()

Do not report duplicate exceptions.

Return Value

$this

protected bool isHttpException(Throwable $e)

Determine if the given exception is an HTTP exception.

Parameters

Throwable $e

Return Value

bool

protected mapLogLevel(Throwable $e)

Map the exception to a log level.

Parameters

Throwable $e

protected LoggerInterface newLogger()

Create a new logger instance.

Return Value

LoggerInterface