From e8f7387fb64ab26f4d850300a58658a893c95027 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Fri, 8 Dec 2023 16:43:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20serialization=20of=20guzzl?= =?UTF-8?q?e=20Middleware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/Utility/GuzzleUtility.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Classes/Utility/GuzzleUtility.php b/Classes/Utility/GuzzleUtility.php index 0701467..8217fe4 100644 --- a/Classes/Utility/GuzzleUtility.php +++ b/Classes/Utility/GuzzleUtility.php @@ -23,13 +23,20 @@ public static function getHandler(): ?Closure // initialize early: so the spatie/async with staticfilecache doesn't kill the process // there is the problem that it has a subprocess where the Container is not initialized fully - $timingUtility = TimingUtility::getInstance(); - $sentryService = GeneralUtility::makeInstance(SentryService::class); - return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($sentryService, $timingUtility, $handler): PromiseInterface { + return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($handler): PromiseInterface { + try { + GeneralUtility::getContainer(); + } catch (\LogicException) { + // container not found: + // than we are most likely in a subprocess (spatie/async) + // and we don't want to initialize the container here! + return $handler($request, $options); + } + $info = $request->getMethod() . ' ' . $request->getUri()->__toString(); - $stop = $timingUtility->stopWatchInternal('http.client', $info); - $request = $sentryService->addSentryTraceHeaders($request, $stop); + $stop = TimingUtility::getInstance()->stopWatchInternal('http.client', $info); + $request = GeneralUtility::makeInstance(SentryService::class)->addSentryTraceHeaders($request, $stop); $handlerPromiseCallback = static function ($responseOrException) use ($request, $stop) { $response = null;