From 495b9b47e74b613360f1f0999ebd698198b904f5 Mon Sep 17 00:00:00 2001 From: Don Hardman Date: Thu, 12 Dec 2024 15:52:54 +0700 Subject: [PATCH] Fix issue with error parsing cuz in non manticore like responses it may contain array --- src/ManticoreSearch/Response.php | 8 ++++---- src/Task/TaskResult.php | 5 ++++- test/BuddyCore/GetManticoreResponseTest.php | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ManticoreSearch/Response.php b/src/ManticoreSearch/Response.php index f4b0117..1c39ac9 100644 --- a/src/ManticoreSearch/Response.php +++ b/src/ManticoreSearch/Response.php @@ -39,9 +39,9 @@ class Response { protected bool $hasData = false; /** - * @var string $error + * @var string|array{type:string,index:string} $error */ - protected string $error = ''; + protected string|array $error = ''; /** * @var string $warning @@ -69,9 +69,9 @@ private function __construct( } /** - * @return ?string + * @return null|string|array{type:string,index:string} */ - public function getError(): ?string { + public function getError(): null|string|array { return $this->error; } diff --git a/src/Task/TaskResult.php b/src/Task/TaskResult.php index 79fd162..a319afc 100644 --- a/src/Task/TaskResult.php +++ b/src/Task/TaskResult.php @@ -70,7 +70,10 @@ public static function fromResponse(Response $response): static { } if ($response->hasError()) { - return new static(null, $response->getError() ?? '', $response->getWarning() ?? ''); + // In this case error only string and may not be array, cuz array is only for raw (non manticore) + /** @var string $error */ + $error = $response->getError() ?? ''; + return new static(null, $error, $response->getWarning() ?? ''); } // No error diff --git a/test/BuddyCore/GetManticoreResponseTest.php b/test/BuddyCore/GetManticoreResponseTest.php index 5827858..02e4dda 100644 --- a/test/BuddyCore/GetManticoreResponseTest.php +++ b/test/BuddyCore/GetManticoreResponseTest.php @@ -94,6 +94,7 @@ public function testFailResponsesToJSONRequest(): void { $this->setUpServer(true); $query = '{"index":"test","id":1,"doc":{"col1" : 1}}'; $mntResp = Response::fromBody(MockManticoreServer::JSON_INSERT_RESPONSE['fail']); + $this->assertEquals( $mntResp, $this->httpClient->sendRequest($query, ManticoreEndpoint::Insert->value)