diff --git a/src/OpenConext/EngineBlockBridge/ErrorReporter.php b/src/OpenConext/EngineBlockBridge/ErrorReporter.php index 85bd9cb2e..04a0a65bf 100644 --- a/src/OpenConext/EngineBlockBridge/ErrorReporter.php +++ b/src/OpenConext/EngineBlockBridge/ErrorReporter.php @@ -27,6 +27,7 @@ use OpenConext\EngineBlock\Service\FeedbackStateHelperInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Throwable; class ErrorReporter { @@ -66,6 +67,10 @@ public function reportError(Exception $exception, string $messageSuffix): void try { $this->storeSessionFeedback($exception); + } catch (Throwable $sessionException) { + $this->logger->warning( + 'Unable to store feedback info in session: ' . $sessionException->getMessage(), + ); } finally { // flush all messages in queue, something went wrong! $this->engineBlockApplicationSingleton->flushLog('An error was caught'); diff --git a/tests/unit/OpenConext/EngineBlockBridge/ErrorReporterTest.php b/tests/unit/OpenConext/EngineBlockBridge/ErrorReporterTest.php index dfe1e810b..fc390936c 100644 --- a/tests/unit/OpenConext/EngineBlockBridge/ErrorReporterTest.php +++ b/tests/unit/OpenConext/EngineBlockBridge/ErrorReporterTest.php @@ -142,4 +142,16 @@ public function it_stores_the_pep_policy_decision_in_the_session(): void self::assertSame($decision, $this->session->get('error_authorization_policy_decision')); } + + #[Test] + public function it_does_not_propagate_exceptions_thrown_while_storing_feedback_in_the_session(): void + { + $this->feedbackInfoCollector + ->shouldReceive('collect') + ->andThrow(new Exception('Failed to start the session because headers have already been sent')); + + $this->applicationSingleton->shouldReceive('flushLog')->with('An error was caught')->once(); + + $this->reporter->reportError(new Exception('test'), ''); + } }