class Handler extends Handler

internal  
 

Traits

Constants

REPORTED_EXCEPTION_MAP_CONTEXT_KEY

Context key for the per-request reported exception deduplication map.

AFTER_RESPONSE_CONTEXT_KEY

Context key for after-response callbacks.

CURRENTLY_REPORTING_CONTEXT_KEY

Context key for the exception currently being reported.

Properties

protected Throwable>> $dontReport

A list of the exception types that are not reported.

from  Handler
protected ReportableHandler[] $reportCallbacks

The callbacks that should be used during reporting.

from  Handler
protected array $contextCallbacks

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

from  Handler
protected Closure[] $dontReportCallbacks

The callbacks that should be used to determine if an exception should not be reported.

from  Handler
protected Throwable>> $dontRetry

A list of the exception types that should stop job retries.

from  Handler
protected Closure> $dontRetryCallbacks

The callbacks that inspect exceptions to determine if they should stop job retries.

from  Handler
protected Closure[] $throttleCallbacks

The callbacks that should be used to throttle reportable exceptions.

from  Handler
protected bool $hashThrottleKeys

Indicate that throttle keys should be hashed.

from  Handler
protected Closure[] $renderCallbacks

The callbacks that should be used during rendering.

from  Handler
protected null|callable $shouldRenderJsonWhenCallback

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

from  Handler
protected null|callable $finalizeResponseCallback

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

from  Handler
protected Closure> $exceptionMap

The registered exception mappings.

from  Handler
protected LogLevel::*> $levels

A map of exceptions with their corresponding custom log levels.

from  Handler
protected RequestExceptionInterface>|Throwable>> $internalDontReport

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

from  Handler
protected array<int, string> $dontFlash

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

from  Handler
protected bool $withoutDuplicates

Indicate that an exception instance should only be reported once.

from  Handler

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.

array
closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

__construct(Container $container)

Create a new exception handler instance.

from  Handler
void
register()

Register the exception handling callbacks for the application.

from  Handler
reportable(callable $reportUsing)

Register a reportable callback.

from  Handler
renderable(callable $renderUsing)

Register a renderable callback.

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

Register a new exception mapping.

from  Handler
dontReport(array|string $exceptions)

Indicate that the given exception type should not be reported.

from  Handler
dontReportWhen(callable $dontReportWhen)

Register a callback to determine if an exception should not be reported.

from  Handler
ignore(array|string $exceptions)

Indicate that the given exception type should not be reported.

from  Handler
dontRetry(array|string $exceptions)

Indicate that jobs should stop retrying for the given exception types.

from  Handler
dontRetryWhen(callable $dontRetryWhen)

Register a callback to determine if jobs should stop retrying for an exception.

from  Handler
bool
shouldStopRetries(Throwable $e)

Determine if jobs should stop retrying for the given exception.

from  Handler
dontFlash(array|string $attributes)

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

from  Handler
level(string $type, string $level)

Set the log level for the given exception type.

from  Handler
void
report(Throwable $e)

Report or log an exception.

from  Handler
void
reportThrowable(Throwable $e)

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

from  Handler
bool
isReporting(Throwable $e)

Determine if the given exception is being reported by this coroutine.

from  Handler
void
reportedException(Throwable $e)

Mark the given exception as reported.

from  Handler
bool
hasReportedException(Throwable $e)

Determine if the given exception has already been reported.

from  Handler
WeakMap
reportedExceptionMap()

Get the reported exception map for the current request.

from  Handler
bool
shouldReport(Throwable $e)

Determine if the exception should be reported.

from  Handler
bool
shouldntReport(Throwable $e)

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

from  Handler
Lottery|Limit|null
throttle(Throwable $e)

Throttle the given exception.

from  Handler
throttleUsing(callable $throttleUsing)

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

from  Handler
stopIgnoring(array|string $exceptions)

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

from  Handler
array
buildExceptionContext(Throwable $e)

Create the context array for logging the given exception.

from  Handler
array
buildContextForException(Throwable $e)

Create the context for the given exception.

from  Handler
array
exceptionContext(Throwable $e)

Get the default exception context variables for logging.

from  Handler
array
context()

Get the default context variables for logging.

from  Handler
buildContextUsing(Closure $contextCallback)

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

from  Handler
Response
render(Request $request, Throwable $e)

Render an exception into an HTTP response.

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

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

from  Handler
void
afterResponse(callable $callback)

Register a callback to be called after an HTTP error response is rendered.

from  Handler
array
afterResponseCallbacks()

Get the callbacks that should be called after an HTTP error response is rendered.

from  Handler
respondUsing(callable $callback)

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

from  Handler
prepareException(Throwable $e)

Prepare exception for rendering.

from  Handler
mapException(Throwable $e)

Map the exception using a registered mapper if possible.

from  Handler
Response|null
renderViaCallbacks(Request $request, Throwable $e)

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

from  Handler
renderExceptionResponse(Request $request, Throwable $e)

Render a default exception response if any.

from  Handler
unauthenticated(Request $request, AuthenticationException $exception)

Convert an authentication exception into a response.

from  Handler
Response
convertValidationExceptionToResponse(ValidationException $e, Request $request)

Create a response object from the given validation exception.

from  Handler
invalid(Request $request, ValidationException $exception)

Convert a validation exception into a response.

from  Handler
invalidJson(Request $request, ValidationException $exception)

Convert a validation exception into a JSON response.

from  Handler
bool
shouldReturnJson(Request $request, Throwable $e)

Determine if the exception handler response should be JSON.

from  Handler
shouldRenderJsonWhen(callable $callback)

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

from  Handler
prepareResponse(Request $request, Throwable $e)

Prepare a response for the given exception.

from  Handler
Response
convertExceptionToResponse(Throwable $e)

Create a Symfony response for the given exception.

from  Handler
string
renderExceptionContent(Throwable $e)

Get the response content for the given exception.

from  Handler
string
renderExceptionWithCustomRenderer(Throwable $e)

Render an exception to a string using the registered ExceptionRenderer.

from  Handler
string
renderExceptionWithSymfony(Throwable $e, bool $debug)

Render an exception to a string using Symfony.

from  Handler
Response
renderHttpException(HttpExceptionInterface $e)

Render the given HttpException.

from  Handler
void
registerErrorViewPaths()

Register the error template hint paths.

from  Handler
string|null
getHttpExceptionView(HttpExceptionInterface $e)

Get the view used to render HTTP exceptions.

from  Handler
toHypervelResponse(Response $response, Throwable $e)

Map the given exception into a Hypervel response.

from  Handler
prepareJsonResponse(Request $request, Throwable $e)

Prepare a JSON response for the given exception.

from  Handler
array
convertExceptionToArray(Throwable $e)

Convert the given exception to an array.

from  Handler
void
renderForConsole(OutputInterface $output, Throwable $e)

Render an exception to the console.

from  Handler
dontReportDuplicates()

Do not report duplicate exceptions.

from  Handler
bool
isHttpException(Throwable $e)

Determine if the given exception is an HTTP exception.

from  Handler
string
mapLogLevel(Throwable $e)

Map the exception to a log level.

from  Handler
LoggerInterface
newLogger()

Create a new logger instance.

from  Handler

Details

in ReflectsClosures at line 25
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

in ReflectsClosures at line 48
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

in ReflectsClosures at line 74
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

in ReflectsClosures at line 94
protected array closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

in Handler at line 215
__construct(Container $container)

Create a new exception handler instance.

Parameters

Container $container

in Handler at line 224
void register()

Register the exception handling callbacks for the application.

Return Value

void

in Handler at line 231
ReportableHandler reportable(callable $reportUsing)

Register a reportable callback.

Parameters

callable $reportUsing

Return Value

ReportableHandler

in Handler at line 245
Handler renderable(callable $renderUsing)

Register a renderable callback.

Parameters

callable $renderUsing

Return Value

Handler

in Handler at line 261
Handler map(callable|string $from, Closure|string|null $to = null)

Register a new exception mapping.

Parameters

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

Return Value

Handler

Exceptions

InvalidArgumentException

in Handler at line 285
Handler dontReport(array|string $exceptions)

Indicate that the given exception type should not be reported.

Alias of "ignore".

Parameters

array|string $exceptions

Return Value

Handler

in Handler at line 295
Handler dontReportWhen(callable $dontReportWhen)

Register a callback to determine if an exception should not be reported.

Parameters

callable $dontReportWhen

Return Value

Handler

in Handler at line 309
Handler ignore(array|string $exceptions)

Indicate that the given exception type should not be reported.

Parameters

array|string $exceptions

Return Value

Handler

in Handler at line 324
Handler dontRetry(array|string $exceptions)

Indicate that jobs should stop retrying for the given exception types.

Boot-only. The exception types persist on the shared handler and affect every subsequently failed job in the worker.

Parameters

array|string $exceptions

Return Value

Handler

in Handler at line 343
Handler dontRetryWhen(callable $dontRetryWhen)

Register a callback to determine if jobs should stop retrying for an exception.

Boot-only. The callback persists on the shared handler and is considered for every subsequently failed job in the worker.

Parameters

callable $dontRetryWhen

Return Value

Handler

in Handler at line 357
bool shouldStopRetries(Throwable $e)

Determine if jobs should stop retrying for the given exception.

Parameters

Throwable $e

Return Value

bool

in Handler at line 414
Handler 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

Handler

in Handler at line 429
Handler level(string $type, string $level)

Set the log level for the given exception type.

Parameters

string $type
string $level

Return Value

Handler

in Handler at line 441
void report(Throwable $e)

Report or log an exception.

Parameters

Throwable $e

Return Value

void

Exceptions

Throwable

in Handler at line 457
protected void reportThrowable(Throwable $e)

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

Parameters

Throwable $e

Return Value

void

Exceptions

Throwable

in Handler at line 507
bool isReporting(Throwable $e)

Determine if the given exception is being reported by this coroutine.

Parameters

Throwable $e

Return Value

bool

in Handler at line 519
protected void reportedException(Throwable $e)

Mark the given exception as reported.

Parameters

Throwable $e

Return Value

void

in Handler at line 527
protected bool hasReportedException(Throwable $e)

Determine if the given exception has already been reported.

Parameters

Throwable $e

Return Value

bool

in Handler at line 535
protected WeakMap reportedExceptionMap()

Get the reported exception map for the current request.

Return Value

WeakMap

in Handler at line 550
bool shouldReport(Throwable $e)

Determine if the exception should be reported.

Parameters

Throwable $e

Return Value

bool

in Handler at line 558
protected bool shouldntReport(Throwable $e)

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

Parameters

Throwable $e

Return Value

bool

in Handler at line 601
protected Lottery|Limit|null throttle(Throwable $e)

Throttle the given exception.

Parameters

Throwable $e

Return Value

Lottery|Limit|null

in Handler at line 621
Handler throttleUsing(callable $throttleUsing)

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

Parameters

callable $throttleUsing

Return Value

Handler

in Handler at line 635
Handler stopIgnoring(array|string $exceptions)

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

Parameters

array|string $exceptions

Return Value

Handler

in Handler at line 655
protected array buildExceptionContext(Throwable $e)

Create the context array for logging the given exception.

Parameters

Throwable $e

Return Value

array

in Handler at line 669
array buildContextForException(Throwable $e)

Create the context for the given exception.

Parameters

Throwable $e

Return Value

array

in Handler at line 677
protected array exceptionContext(Throwable $e)

Get the default exception context variables for logging.

Parameters

Throwable $e

Return Value

array

in Handler at line 695
protected array context()

Get the default context variables for logging.

Return Value

array

in Handler at line 709
Handler buildContextUsing(Closure $contextCallback)

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

Parameters

Closure $contextCallback

Return Value

Handler

in Handler at line 721
Response render(Request $request, Throwable $e)

Render an exception into an HTTP response.

Parameters

Request $request
Throwable $e

Return Value

Response

Exceptions

Throwable

in Handler at line 754
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

in Handler at line 772
void afterResponse(callable $callback)

Register a callback to be called after an HTTP error response is rendered.

Parameters

callable $callback

Return Value

void

in Handler at line 785
protected array afterResponseCallbacks()

Get the callbacks that should be called after an HTTP error response is rendered.

Return Value

array

in Handler at line 793
Handler respondUsing(callable $callback)

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

Parameters

callable $callback

Return Value

Handler

in Handler at line 803
protected Throwable prepareException(Throwable $e)

Prepare exception for rendering.

Parameters

Throwable $e

Return Value

Throwable

in Handler at line 826
protected Throwable mapException(Throwable $e)

Map the exception using a registered mapper if possible.

Parameters

Throwable $e

Return Value

Throwable

in Handler at line 846
protected Response|null renderViaCallbacks(Request $request, Throwable $e)

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

Parameters

Request $request
Throwable $e

Return Value

Response|null

in Handler at line 864
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

in Handler at line 874
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

in Handler at line 892
protected Response convertValidationExceptionToResponse(ValidationException $e, Request $request)

Create a response object from the given validation exception.

Parameters

ValidationException $e
Request $request

Return Value

Response

in Handler at line 906
protected RedirectResponse invalid(Request $request, ValidationException $exception)

Convert a validation exception into a response.

Parameters

Request $request
ValidationException $exception

Return Value

RedirectResponse

in Handler at line 921
protected JsonResponse invalidJson(Request $request, ValidationException $exception)

Convert a validation exception into a JSON response.

Parameters

Request $request
ValidationException $exception

Return Value

JsonResponse

in Handler at line 932
protected bool shouldReturnJson(Request $request, Throwable $e)

Determine if the exception handler response should be JSON.

Parameters

Request $request
Throwable $e

Return Value

bool

in Handler at line 944
Handler shouldRenderJsonWhen(callable $callback)

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

Parameters

callable $callback

Return Value

Handler

in Handler at line 954
protected Response|RedirectResponse prepareResponse(Request $request, Throwable $e)

Prepare a response for the given exception.

Parameters

Request $request
Throwable $e

Return Value

Response|RedirectResponse

in Handler at line 973
protected Response convertExceptionToResponse(Throwable $e)

Create a Symfony response for the given exception.

Parameters

Throwable $e

Return Value

Response

in Handler at line 985
protected string renderExceptionContent(Throwable $e)

Get the response content for the given exception.

Parameters

Throwable $e

Return Value

string

in Handler at line 1006
protected string renderExceptionWithCustomRenderer(Throwable $e)

Render an exception to a string using the registered ExceptionRenderer.

Parameters

Throwable $e

Return Value

string

in Handler at line 1014
protected string renderExceptionWithSymfony(Throwable $e, bool $debug)

Render an exception to a string using Symfony.

Parameters

Throwable $e
bool $debug

Return Value

string

in Handler at line 1026
protected Response renderHttpException(HttpExceptionInterface $e)

Render the given HttpException.

Parameters

HttpExceptionInterface $e

Return Value

Response

Exceptions

Throwable

in Handler at line 1054
protected void registerErrorViewPaths()

Register the error template hint paths.

Return Value

void

in Handler at line 1062
protected string|null getHttpExceptionView(HttpExceptionInterface $e)

Get the view used to render HTTP exceptions.

Parameters

HttpExceptionInterface $e

Return Value

string|null

in Handler at line 1082
protected Response|RedirectResponse toHypervelResponse(Response $response, Throwable $e)

Map the given exception into a Hypervel response.

Parameters

Response $response
Throwable $e

Return Value

Response|RedirectResponse

in Handler at line 1104
protected JsonResponse prepareJsonResponse(Request $request, Throwable $e)

Prepare a JSON response for the given exception.

Parameters

Request $request
Throwable $e

Return Value

JsonResponse

in Handler at line 1117
protected array convertExceptionToArray(Throwable $e)

Convert the given exception to an array.

Parameters

Throwable $e

Return Value

array

in Handler at line 1133
void renderForConsole(OutputInterface $output, Throwable $e)

Render an exception to the console.

Parameters

OutputInterface $output
Throwable $e

Return Value

void

in Handler at line 1158
Handler dontReportDuplicates()

Do not report duplicate exceptions.

Return Value

Handler

in Handler at line 1170
protected bool isHttpException(Throwable $e)

Determine if the given exception is an HTTP exception.

Parameters

Throwable $e

Return Value

bool

in Handler at line 1180
protected string mapLogLevel(Throwable $e)

Map the exception to a log level.

Parameters

Throwable $e

Return Value

string

in Handler at line 1192
protected LoggerInterface newLogger()

Create a new logger instance.

Return Value

LoggerInterface