Skip to content

Commit e99e761

Browse files
committed
check exception has method getStatusCode
This code naively assumed all exception here would have the getStatusCode method; but it does not have to be the case. With this commit we avoid crashing when this assumption does not hold.
1 parent f2253b1 commit e99e761

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

symfony-server/src/EventListener/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __invoke(Exceptionevent $event): void {
1818
$response->setStatusCode(Response::HTTP_NOT_FOUND);
1919
$response->setContent("Not found");
2020
$event->setResponse($response);
21-
} else if ($exception->getStatusCode() === Response::HTTP_UNAUTHORIZED) {
21+
} else if (method_exists($exception, "getStatusCode") && $exception->getStatusCode() === Response::HTTP_UNAUTHORIZED) {
2222
$this->logger->warning("Caught unauthorized access");
2323
$response = new Response();
2424
$response->setStatusCode(Response::HTTP_UNAUTHORIZED);

0 commit comments

Comments
 (0)