Skip to content

Commit

Permalink
Fix issue with error parsing cuz in non manticore like responses it m…
Browse files Browse the repository at this point in the history
…ay contain array
  • Loading branch information
donhardman committed Dec 12, 2024
1 parent e3b33b3 commit 495b9b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ManticoreSearch/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Task/TaskResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/BuddyCore/GetManticoreResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 495b9b4

Please sign in to comment.