Problem/Motivation

I signed up for a free trial of Algolia in order to test out the functionality. That trial has since expired, and when I try to connect to the Algolia API it returns an error.

This module does not handle this error in the way that I would expect; when I save some content that causes the index to be updated, instead of catching and logging the Algolia error, it causes a fatal error which halts the whole site. I would expect it to just not perform indexing if Algolia is unavailable.

The following is the error I receive:

The website encountered an unexpected error. Please try again later.

AlgoliaSearch\AlgoliaException: Operations quota exceeded, change plan to get more Operations. in AlgoliaSearch\Client->doRequest() (line 992 of /var/www/vhosts/ccw.dev/vendor/algolia/algoliasearch-client-php/src/AlgoliaSearch/Client.php).
AlgoliaSearch\Client->request(Object, 'GET', '/1/indexes/', NULL, NULL, Array, 1, 30) (Line: 291)
AlgoliaSearch\Client->listIndexes() (Line: 139)
Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend->viewSettings() (Line: 182)
Drupal\search_api\Entity\Server->viewSettings() (Line: 269)
theme_search_api_server(Array) (Line: 317)
Drupal\Core\Theme\ThemeManager->render('search_api_server', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

In the file /src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php on line 185 it looks as though the code intends to catch and log any such errors. However this doesn't happen with the error in question as AlgoliaException is not included correctly. Additionally, when I include AlgoliaException, the catch fails as the Html class referred to on line 186 is also not included correctly.

CommentFileSizeAuthor
#2 fatal_error_thrown_when-2883037-2.patch605 bytesmaccath

Comments

maccath created an issue. See original summary.

maccath’s picture

Status: Active » Needs review
StatusFileSize
new605 bytes
legolasbo’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me and solves the issue as well.

  • nikunjkotecha committed b1e2c9e on 8.x-1.x authored by maccath
    Issue #2883037 by maccath: Fatal error thrown when requests to Algolia...
nikunjkotecha’s picture

Assigned: maccath » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.