fix: pass logger explicitly to BookingCreateTrait::handleApiError

This commit is contained in:
Björn Fromme
2026-04-16 13:34:54 +02:00
parent 4d86629315
commit 132329361f
3 changed files with 12 additions and 1 deletions
@@ -80,6 +80,7 @@ class Step3Controller extends AbstractController
if ($inquiryResponse instanceof Notification) {
$this->handleApiError(
$this->logger,
'Booking inquiry failed',
['message' => $inquiryResponse->message],
$inquiryResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuche es erneut oder wende dich an den Kundenservice.',
@@ -113,6 +114,7 @@ class Step3Controller extends AbstractController
}
$this->handleApiError(
$this->logger,
'Booking inquiry validation failed',
['status' => $inquiryResponse->status, 'message' => $inquiryResponse->message],
$errorMessage,
@@ -137,6 +139,7 @@ class Step3Controller extends AbstractController
$deltaBreakdown = $diagnostics['deltaBreakdown'] ?? [];
$this->handleApiError(
$this->logger,
'Price mismatch detected - payload incomplete',
[
'apiTotal' => $apiTotal,
@@ -168,6 +171,7 @@ class Step3Controller extends AbstractController
return $this->redirectToRoute('app_booking_create_step_4');
} catch (TimeoutException $e) {
$this->handleApiError(
$this->logger,
'Booking inquiry timeout',
[
'exception' => $e->getMessage(),
@@ -177,6 +181,7 @@ class Step3Controller extends AbstractController
);
} catch (\Exception $e) {
$this->handleApiError(
$this->logger,
'Booking inquiry exception',
[
'exception' => $e->getMessage(),
@@ -93,6 +93,7 @@ class Step4Controller extends AbstractController
if ($bookingResponse instanceof Notification) {
$this->handleApiError(
$this->logger,
'Booking creation failed - API notification',
['message' => $bookingResponse->message],
$bookingResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuchen es erneut.',
@@ -108,6 +109,7 @@ class Step4Controller extends AbstractController
}
$this->handleApiError(
$this->logger,
'Booking creation unsuccessful',
['status' => $bookingResponse->status, 'message' => $bookingResponse->message],
$errorMessage,
@@ -148,6 +150,7 @@ class Step4Controller extends AbstractController
return $this->redirectToRoute('app_booking_create_success');
} catch (TimeoutException $e) {
$this->handleApiError(
$this->logger,
'Booking creation timeout',
[
'exception' => $e->getMessage(),
@@ -157,6 +160,7 @@ class Step4Controller extends AbstractController
);
} catch (\Exception $e) {
$this->handleApiError(
$this->logger,
'Booking creation exception',
[
'exception' => $e->getMessage(),
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controller\Booking\Traits;
use App\Form\Model\BookingDto;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
@@ -52,11 +53,12 @@ trait BookingCreateTrait
* Handles API errors by logging and adding a flash message.
*/
private function handleApiError(
LoggerInterface $logger,
string $logMessage,
array $context,
string $flashMessage,
): void {
$this->logger->error($logMessage, $context);
$logger->error($logMessage, $context);
$this->addFlash('error', $flashMessage);
}
}