From e4c467b92cce7c62535a7b8110703b6c9145a18d Mon Sep 17 00:00:00 2001 From: Enes Erk <8766722+erkenes@users.noreply.github.com> Date: Fri, 10 Apr 2026 18:49:35 +0200 Subject: [PATCH] BUGFIX: Handle PSR-7 ApiException responses - handle PSR-7 ResponseInterface responses - extract the response body when available (falling back to string cast) - log errors for both associative array and stdClass --- Classes/UpdateAliasJob.php | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/Classes/UpdateAliasJob.php b/Classes/UpdateAliasJob.php index 129526c..25bede8 100644 --- a/Classes/UpdateAliasJob.php +++ b/Classes/UpdateAliasJob.php @@ -22,6 +22,7 @@ use Neos\Flow\Log\Utility\LogEnvironment; use Neos\Flow\Utility\Algorithms; use Psr\Log\LoggerInterface; +use Psr\Http\Message\ResponseInterface; class UpdateAliasJob implements JobInterface { @@ -137,11 +138,43 @@ protected function cleanupOldIndices(): void } } } catch (ApiException $exception) { - $response = json_decode($exception->getResponse(), true, 512, JSON_THROW_ON_ERROR); - if ($response->error instanceof \stdClass) { - $this->logger->error(sprintf('Old indices for alias %s could not be removed. ElasticSearch responded with status %s, saying "%s: %s"', $this->indexPostfix, $response->status, $response->error->type, $response->error->reason), LogEnvironment::fromMethodName(__METHOD__)); + $responseBody = $exception->getResponse() instanceof ResponseInterface + ? $exception->getResponse()->getBody()->__toString() + : (string) $exception->getResponse(); + $response = json_decode($responseBody, true, 512, JSON_THROW_ON_ERROR); + + if (is_array($response)) { + $this->logger->error( + sprintf( + 'Old indices for alias %s could not be removed. ElasticSearch responded with status %s, saying "%s: %s"', + $this->indexPostfix, + $response['status'], + $response['error']['type'], + $response['error']['reason'] + ), + LogEnvironment::fromMethodName(__METHOD__) + ); + } elseif ($response->error instanceof \stdClass) { + $this->logger->error( + sprintf( + 'Old indices for alias %s could not be removed. ElasticSearch responded with status %s, saying "%s: %s"', + $this->indexPostfix, + $response->status, + $response->error->type, + $response->error->reason + ), + LogEnvironment::fromMethodName(__METHOD__) + ); } else { - $this->logger->error(sprintf('Old indices for alias %s could not be removed. ElasticSearch responded with status %s, saying "%s"', $this->indexPostfix, $response->status, $response->error), LogEnvironment::fromMethodName(__METHOD__)); + $this->logger->error( + sprintf( + 'Old indices for alias %s could not be removed. ElasticSearch responded with status %s, saying "%s"', + $this->indexPostfix, + $response->status, + $response->error + ), + LogEnvironment::fromMethodName(__METHOD__) + ); } } }