Skip to content

Commit

Permalink
Check for session existence before retrieving it
Browse files Browse the repository at this point in the history
Calling "getSession()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.
  • Loading branch information
bobvandevijver committed Sep 5, 2022
1 parent dcb0860 commit 81298be
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Handler/AbstractExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public function onKernelException(ExceptionEvent $event)
$backtrace->setFileContent($this->buildBacktrace($event));

// Unset the used session variable
$session = $event->getRequest()->getSession();
$request = $event->getRequest();
$session = $request->hasSession() ? $request->getSession() : null;
if ($session) {
$session->remove(self::SESSION_FILENAME);
$session->set(self::SESSION_ERROR, $exception->getMessage());
Expand Down Expand Up @@ -204,7 +205,7 @@ public function onKernelResponse(ResponseEvent $responseObject)
$response = $responseObject->getResponse();
$request = $responseObject->getRequest();
$statusCode = $response->getStatusCode();
$session = $request->getSession();
$session = $request->hasSession() ? $request->getSession() : null;

if (!$this->configuration->isProductionEnvironment()) {
// no production! -> don't sent an email
Expand Down

0 comments on commit 81298be

Please sign in to comment.