Skip to content

Commit 5197269

Browse files
committed
Fixed ExceptionEvent getThrowable
1 parent 609a0c4 commit 5197269

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/EventSubscriber/ExceptionSubscriber.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ public static function getSubscribedEvents(): array
4848
*/
4949
public function onKernelException(ExceptionEvent $event): void
5050
{
51-
$exception = $event->getException();
51+
$throwable = $event->getThrowable();
5252

5353
if (!$this->kernel->isDebug() && $event->getRequest()->isXmlHttpRequest()) {
5454
$response = new JsonResponse([
5555
'ok' => false,
5656
'error' => [
57-
'message' => $exception->getMessage(),
57+
'message' => $throwable->getMessage(),
5858
],
5959
]);
6060

6161
$event->setResponse($response);
6262
}
6363

64-
if ($exception instanceof AccessDeniedHttpException) {
65-
if (preg_match('/Access Denied by controller annotation @IsGranted\("(.+)"\)/', $exception->getMessage(), $matches)
66-
|| preg_match('/Access Denied by controller annotation @IsGranted\("(.+)", (.+)\)/', $exception->getMessage(), $matches)
64+
if ($throwable instanceof AccessDeniedHttpException) {
65+
if (preg_match('/Access Denied by controller annotation @IsGranted\("(.+)"\)/', $throwable->getMessage(), $matches)
66+
|| preg_match('/Access Denied by controller annotation @IsGranted\("(.+)", (.+)\)/', $throwable->getMessage(), $matches)
6767
) {
6868
$redirectUrl = $this->urlGenerator->generate('admin_access_denied', [
6969
'rule' => strtolower(explode('|', $matches[1])[0]),
@@ -73,8 +73,8 @@ public function onKernelException(ExceptionEvent $event): void
7373
}
7474
}
7575

76-
if ($exception instanceof NotFoundHttpException) {
77-
if (preg_match('/App:(\w+) object not found by the @ParamConverter annotation/', $exception->getMessage(), $matches)) {
76+
if ($throwable instanceof NotFoundHttpException) {
77+
if (preg_match('/App:(\w+) object not found by the @ParamConverter annotation/', $throwable->getMessage(), $matches)) {
7878
$redirectUrl = $this->urlGenerator->generate('admin_missing_entity', [
7979
'object' => strtolower($matches[1]),
8080
]);

0 commit comments

Comments
 (0)