Catch errors when trying to retrieve indexes

Created on 22 August 2023, about 1 year ago
Updated 5 September 2023, about 1 year ago

Problem/Motivation

When retrieving an index produces errors, there is no error logged whatsoever.

Proposed resolution

Catch errors that might arise when retrieving an index.

Remaining tasks

The following might be a good starting point:

diff --git a/src/Api/MeiliSearchApiService.php b/src/Api/MeiliSearchApiService.php
index 3e1dd16..f304eff 100644
--- a/src/Api/MeiliSearchApiService.php
+++ b/src/Api/MeiliSearchApiService.php
@@ -117,10 +117,15 @@ class MeiliSearchApiService implements MeiliSearchApiServiceInterface {
       return [];
     }

-    $index = $this->getIndex($index_name);
-    if ($index) {
-      return $index->search($query, $options);
+    try {
+      $index = $this->getIndex($index_name);
+      if ($index) {
+        return $index->search($query, $options);
+      }
+    } catch (\Exception $e) { //TODO: probably catch/handle API vs. timeout exception differently ?
+      throw new MeiliSearchApiException($e->getMessage(), $e->getCode(), $e);
     }
+
     return [];
   }
📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇦🇹Austria tgoeg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024