Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/Driver/OpenSearch/OpenSearchHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,38 @@ public function request(string $method, string $uri, mixed $body = null): stdCla

$statusCode = $response->getStatusCode();
if ($statusCode < 200 || $statusCode > 299) {
$parsed = null;
try {
$parsed = $this->parseResponse($response);
} catch (Exception) {}
throw new HttpErrorResponseException($parsed, "OpenSearch returned status code " . $statusCode, $statusCode);
$this->handleErrorResponse($response);
}

return $this->parseResponse($response);
}

/**
* @param ResponseInterface $response
* @return void
* @throws HttpErrorResponseException
*/
protected function handleErrorResponse(ResponseInterface $response): void
{
$statusCode = $response->getStatusCode();
try {
$parsed = $this->parseResponse($response);
} catch (Exception) {
throw new HttpErrorResponseException(null, "OpenSearch returned status code " . $statusCode, $statusCode);
}

$type = $parsed->error?->type ?? null;
$reason = $parsed->error?->reason ?? null;
$message = "OpenSearch returned error " . $statusCode;
if ($type !== null) {
$message .= " [" . $type . "]";
}
if ($reason !== null) {
$message .= " " . $reason;
}
throw new HttpErrorResponseException($parsed, $message, $statusCode);
}

/**
* @param ResponseInterface $response
* @return stdClass
Expand Down
Loading