function HttpKernel::handleThrowable
Handles a throwable by trying to convert it to a Response.
2 calls to HttpKernel::handleThrowable()
- HttpKernel::handle in vendor/
symfony/ http-kernel/ HttpKernel.php - Handles a Request to convert it to a Response.
- HttpKernel::terminateWithException in vendor/
symfony/ http-kernel/ HttpKernel.php - @internal
File
-
vendor/
symfony/ http-kernel/ HttpKernel.php, line 238
Class
- HttpKernel
- HttpKernel notifies events to convert a Request object to a Response one.
Namespace
Symfony\Component\HttpKernelCode
private function handleThrowable(\Throwable $e, Request $request, int $type) : Response {
$event = new ExceptionEvent($this, $request, $type, $e, isKernelTerminating: $this->terminating);
$this->dispatcher
->dispatch($event, KernelEvents::EXCEPTION);
// a listener might have replaced the exception
$e = $event->getThrowable();
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);
throw $e;
}
$response = $event->getResponse();
// the developer asked for a specific status code
if (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
// ensure that we actually have an error response
if ($e instanceof HttpExceptionInterface) {
// keep the HTTP status code and headers
$response->setStatusCode($e->getStatusCode());
$response->headers
->add($e->getHeaders());
}
else {
$response->setStatusCode(500);
}
}
try {
return $this->filterResponse($response, $request, $type);
} catch (\Throwable $e) {
if ($e instanceof \Error && !$this->handleAllThrowables) {
throw $e;
}
return $response;
}
}