This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit b21f088409fe01f358f7227aa4c2e7393bbe91bc
Author: Daniel Gruno <[email protected]>
AuthorDate: Wed Nov 3 19:55:27 2021 +0100

    Add a timeout error class for searches
---
 server/plugins/database.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/server/plugins/database.py b/server/plugins/database.py
index 7e41d53..f322861 100644
--- a/server/plugins/database.py
+++ b/server/plugins/database.py
@@ -22,10 +22,15 @@ This is the Database library stub for Pony Mail codename 
Foal
 import uuid
 import typing
 import elasticsearch
+import elasticsearch.exceptions
 
 import plugins.configuration
 
 
+class Timeout (elasticsearch.exceptions.ConnectionTimeout):
+    """Database timeout exception"""
+
+
 class DBNames:
     def __init__(self, dbprefix):
         self.mbox = f"{dbprefix}-mbox"
@@ -67,8 +72,11 @@ class Database:
     async def search(self, index="", **kwargs):
         if not index:
             index = self.dbs.mbox
-        res = await self.client.search(index=index, **kwargs)
-        return res
+        try:
+            res = await self.client.search(index=index, **kwargs)
+            return res
+        except elasticsearch.exceptions.ConnectionTimeout as e:
+            raise Timeout(e)
 
     async def get(self, index="", **kwargs):
         if not index:

Reply via email to