From ca580a2bf42559366120f195bf8fbb89026b0826 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 22 Nov 2024 10:08:10 +0100 Subject: [PATCH] fix(federation): Allow federation error responses to be read twice Signed-off-by: Joas Schilling --- lib/Federation/Proxy/TalkV1/ProxyRequest.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Federation/Proxy/TalkV1/ProxyRequest.php b/lib/Federation/Proxy/TalkV1/ProxyRequest.php index ea5d606bc2f..8b25fc3020e 100644 --- a/lib/Federation/Proxy/TalkV1/ProxyRequest.php +++ b/lib/Federation/Proxy/TalkV1/ProxyRequest.php @@ -118,10 +118,11 @@ protected function request( $requestOptions ); } catch (ClientException $e) { + $guzzleResponse = $e->getResponse(); + $body = $guzzleResponse->getBody()->getContents(); $status = $e->getResponse()->getStatusCode(); try { - $body = $e->getResponse()->getBody()->getContents(); $data = json_decode($body, true, flags: JSON_THROW_ON_ERROR); if (!is_array($data)) { throw new \RuntimeException('JSON response is not an array'); @@ -132,7 +133,15 @@ protected function request( $clientException = new RemoteClientException($e->getMessage(), $status, $e, $data); $this->logger->debug('Client error from remote', ['exception' => $clientException]); - return new Response($e->getResponse(), false); + + /** @psalm-suppress UndefinedClass,InvalidArgument */ + return new Response(new \GuzzleHttp\Psr7\Response( + $guzzleResponse->getStatusCode(), + $guzzleResponse->getHeaders(), + $body, + $guzzleResponse->getProtocolVersion(), + $guzzleResponse->getReasonPhrase(), + ), false); } catch (ServerException|\Throwable $e) { $serverException = new CannotReachRemoteException($e->getMessage(), $e->getCode(), $e); $this->logger->error('Could not reach remote', ['exception' => $serverException]);