Browse Source

Some error handling

Chimo 6 months ago
parent
commit
88d4bfb779
1 changed files with 19 additions and 3 deletions
  1. 19
    3
      lib/ElasticSearch.php

+ 19
- 3
lib/ElasticSearch.php View File

@@ -87,9 +87,14 @@ class ElasticSearch extends SearchEngine
87 87
                 ]
88 88
             ];
89 89
 
90
-            $response = $this->client->indices()->create($params);
91
-
92
-            // TODO: Parse response, handle errors
90
+            try {
91
+                $this->client->indices()->create($params);
92
+            } catch(Exception $e) {
93
+                common_log(
94
+                    LOG_ERROR,
95
+                    "Unable to create index existing $this->index_name: $e->getMessage()"
96
+                );
97
+            }
93 98
         }
94 99
     }
95 100
 
@@ -154,6 +159,17 @@ class ElasticSearch extends SearchEngine
154 159
         $author = Profile::getKV('id', $notice->profile_id);
155 160
         $webfinger = $author->getAcctUri(false);
156 161
 
162
+        try {
163
+            $object_type = $notice->getObjectType();
164
+        } catch(NoObjectTypeException $e) {
165
+            common_log(
166
+                LOG_INFO,
167
+                "Notice $notice->getID() doesn't have an object_type"
168
+            );
169
+
170
+            $object_type = null;
171
+        }
172
+
157 173
         $params = [
158 174
             'index' => $this->index_name,
159 175
             'type' => $this->index_type,