Skip to content

Commit 81298be

Browse files
Check for session existence before retrieving it
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.
1 parent dcb0860 commit 81298be

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Handler/AbstractExceptionHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public function onKernelException(ExceptionEvent $event)
113113
$backtrace->setFileContent($this->buildBacktrace($event));
114114

115115
// Unset the used session variable
116-
$session = $event->getRequest()->getSession();
116+
$request = $event->getRequest();
117+
$session = $request->hasSession() ? $request->getSession() : null;
117118
if ($session) {
118119
$session->remove(self::SESSION_FILENAME);
119120
$session->set(self::SESSION_ERROR, $exception->getMessage());
@@ -204,7 +205,7 @@ public function onKernelResponse(ResponseEvent $responseObject)
204205
$response = $responseObject->getResponse();
205206
$request = $responseObject->getRequest();
206207
$statusCode = $response->getStatusCode();
207-
$session = $request->getSession();
208+
$session = $request->hasSession() ? $request->getSession() : null;
208209

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

0 commit comments

Comments
 (0)