Skip to content

Commit

Permalink
[Fix] v1.2.2 Session check before accessing (#5)
Browse files Browse the repository at this point in the history
* check if session exists before accessing it

* added return value
  • Loading branch information
sinansoezen authored Aug 31, 2021
1 parent addab7d commit 2b1b5d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ExceptionEnricher/ExceptionEnricherBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ExceptionEnricherBundle extends Bundle
{
public function getContainerExtension()
public function getContainerExtension(): ExceptionEnricherExtension
{
return new ExceptionEnricherExtension();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __invoke(array $record): array
$record['extra']['request_ip'] = $this->requestStack->getMainRequest()->getClientIp();
}

if ($this->requestStack->getSession() && $this->requestStack->getSession()->getId()) {
if ($this->requestStack->getCurrentRequest()->hasSession() && $this->requestStack->getSession()->getId()) {
$record['extra']['session_id'] = $this->requestStack->getSession()->getId();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function testFullProcessor()
$request->getClientIp()->willReturn('127.0.0.1')->shouldBeCalled();
$request->getMethod()->willReturn('GET')->shouldBeCalled();
$request->getRequestUri()->willReturn('/testroute/')->shouldBeCalled();
$request->hasSession()->willReturn(true)->shouldBeCalled();

$session = $this->prophesize(SessionInterface::class);
$session->getId()->willReturn('39d9f31fb12441428031e26d2f83ab6e')->shouldBeCalled();
Expand Down Expand Up @@ -75,12 +76,12 @@ public function testFullProcessor()
$this->assertSame('39d9f31fb12441428031e26d2f83ab6e', $record['extra']['session_id']);
}

private function createRecord($level = Logger::ERROR, $message = 'An Exception has been encountered.'): array
private function createRecord(): array
{
return [
'message' => $message,
'level' => $level,
'level_name' => Logger::getLevelName($level),
'message' => 'An Exception has been encountered.',
'level' => Logger::ERROR,
'level_name' => Logger::getLevelName(Logger::ERROR),
'channel' => 'test',
'datetime' => new DateTimeImmutable('now'),
'extra' => [],
Expand Down

0 comments on commit 2b1b5d7

Please sign in to comment.