- Algolia Client Version: 3.2.0
- Language Version: 8.1.2
Description
It seems like the current implementation of the exception is misleading:
|
try { |
|
$request = $this->createRequest( |
|
$method, |
|
$uri, |
|
$requestOptions->getHeaders(), |
|
$body |
|
); |
|
|
|
$this->log(LogLevel::DEBUG, 'Sending request.', $logParams); |
|
|
|
$response = $this->http->sendRequest( |
|
$request, |
|
$timeout * $retry, |
|
$requestOptions->getConnectTimeout() * $retry |
|
); |
|
|
|
$responseBody = $this->handleResponse($response, $request); |
|
|
|
$logParams['response'] = $responseBody; |
|
$this->log(LogLevel::DEBUG, 'Response received.', $logParams); |
|
|
|
return $responseBody; |
|
} catch (RetriableException $e) { |
|
$this->log(LogLevel::DEBUG, 'Host failed.', array_merge($logParams, [ |
|
'description' => $e->getMessage(), |
|
])); |
|
|
|
$this->clusterHosts->failed($host); |
|
} catch (BadRequestException $e) { |
|
unset($logParams['body'], $logParams['headers']); |
|
$logParams['description'] = $e->getMessage(); |
|
$this->log(LogLevel::WARNING, 'Bad request.', $logParams); |
|
|
|
throw $e; |
|
} catch (\Exception $e) { |
|
unset($logParams['body'], $logParams['headers']); |
|
$logParams['description'] = $e->getMessage(); |
|
$this->log(LogLevel::ERROR, 'Generic error.', $logParams); |
|
|
|
throw $e; |
|
} |
|
|
|
$retry++; |
|
} |
|
|
|
throw new UnreachableException(); |
To day, I got the following exception Impossible to connect, please check your Algolia Application Id.
Turning on logging revealed that this was in fact due to a missing feature on a new infrastructure we are testing:
^ array:3 [
"level" => "debug"
"message" => "Algolia API client: Host failed."
"context" => array:7 [
"body" => array:1 [
"numericFilters" => "document_update_time < 1650806228"
]
"headers" => array:4 [
"X-Algolia-Application-Id" => "redacted"
"X-Algolia-API-Key" => "redacted"
"User-Agent" => "Algolia for PHP (3.2.0); PHP (8.1.2); Guzzle (7)"
"Content-Type" => "application/json"
]
"method" => "POST"
"query" => []
"retryNumber" => 4
"host" => "https://mlnqxjqtya-1.algolianet.com/1/indexes/int_products_gb/deleteByQuery"
"description" => "Retriable failure on mlnqxjqtya-1.algolianet.com: Not Implemented"
]
]
I would expect never to get an exception that is plain wrong. Before getting this issue, I had a problem where my index name was wrong, but it was diagnosed in the same way: Impossible to connect, please check your Algolia Application Id..
What I would expect would be the last error to be remembered and used in the exception message. Also, the exception type is wrong: the host was not unreachable, it was missing a feature.
Description
It seems like the current implementation of the exception is misleading:
algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php
Lines 151 to 196 in ffef644
To day, I got the following exception
Impossible to connect, please check your Algolia Application Id.Turning on logging revealed that this was in fact due to a missing feature on a new infrastructure we are testing:
I would expect never to get an exception that is plain wrong. Before getting this issue, I had a problem where my index name was wrong, but it was diagnosed in the same way:
Impossible to connect, please check your Algolia Application Id..What I would expect would be the last error to be remembered and used in the exception message. Also, the exception type is wrong: the host was not unreachable, it was missing a feature.