From 0c5c1ad04d3d84ecfb128c0f5dd2113bf3a59b39 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Wed, 10 Jul 2024 17:22:39 +0200 Subject: [PATCH] fix: fix error when exception has no previous exception --- myparcelnl.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/myparcelnl.php b/myparcelnl.php index 11017900..fe2f348a 100644 --- a/myparcelnl.php +++ b/myparcelnl.php @@ -218,17 +218,22 @@ private function withErrorHandling( if ($this->hasPdk) { $previous = $e->getPrevious(); - Logger::error($e->getMessage(), [ - 'file' => $e->getFile(), - 'line' => $e->getLine(), - 'trace' => $e->getTrace(), - 'previous' => [ + $context = [ + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'trace' => $e->getTrace(), + ]; + + if ($previous) { + $context['previous'] = [ 'message' => $previous->getMessage(), 'file' => $previous->getFile(), 'line' => $previous->getLine(), 'trace' => $previous->getTrace(), - ], - ]); + ]; + } + + Logger::error($e->getMessage(), $context); } $formattedMessage = sprintf(