Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotFoundException too general to catch #700

Open
JeroenBakker opened this issue Mar 2, 2022 · 0 comments
Open

NotFoundException too general to catch #700

JeroenBakker opened this issue Mar 2, 2022 · 0 comments

Comments

@JeroenBakker
Copy link

  • Algolia Client Version: 3.2.0
  • Language Version: 7.4

Description

Hi there,

I'm using the client to retrieve product recommendations based on the bought-together and related-products models.
Some of our indexes don't have enough events to train models so they shouldn't be used for recommendations, but it's possible that we misconfigure this somewhere, or that the number of events drops for indexes that did have enough events at some point.

Where there's no trained model (but the index does exist) I get the following exception:

(stack trace limited to vendor namespace only)

Fatal error:  Uncaught Algolia\AlgoliaSearch\Exceptions\NotFoundException: Index ai_recommend_webshop-products-se:related-products.indice.bin does not exist in ./vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php:217
Stack trace:
#0 ./vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php(167): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->handleResponse()
#1 ./vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php(101): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->request()
#2 ./vendor/algolia/algoliasearch-client-php/src/RecommendClient.php(85): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->write()
  thrown in ./vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php on line 217

I would like to catch this kind of exception, but it is identical in type to the exception I get when the index doesn't exist:

Fatal error:  Uncaught Algolia\AlgoliaSearch\Exceptions\NotFoundException: Index does not exist in ./vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php:217

Ideally this would be a different kind of exception so my code can handle missing/untrained models but doesn't handle missing indexes since that's a much more grave error.
Attempting to parse the exception message seems a little unreliable, as those messages might change without us noticing.

Steps To Reproduce

  1. Request a recommendation from an existing index without a trained model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant