diff options
author | Kristofer Hallin <kristofer@sunet.se> | 2021-12-17 10:18:42 +0100 |
---|---|---|
committer | Kristofer Hallin <kristofer@sunet.se> | 2021-12-17 10:18:42 +0100 |
commit | a3b5cde94981b9a98d367004b4c513c81e5870e4 (patch) | |
tree | 268d5e33b0fb63bb010b30f6e9879036fe699c1e /src | |
parent | 41aed82fafc6aea842cfb6203a3994d6c4a9d8db (diff) |
Only retry the database connection if we get an ConnectionError exception.
Diffstat (limited to 'src')
-rwxr-xr-x | src/main.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/main.py b/src/main.py index ad8aada..f95a09c 100755 --- a/src/main.py +++ b/src/main.py @@ -11,6 +11,7 @@ from pydantic import BaseModel from index import CouchIindex import time from db import DictDB +import requests app = FastAPI() @@ -35,9 +36,9 @@ async def mock_x_total_count_header(request: Request, call_next): for i in range(10): try: db = DictDB() - except Exception: - print( - f'Database not responding, will try again soon. Attempt {i + 1} of 10.') + except requests.exceptions.ConnectionError: + print(f'Database not responding, will try again soon.' + + 'Attempt {i + 1} of 10.') else: break time.sleep(10) |