From a3b5cde94981b9a98d367004b4c513c81e5870e4 Mon Sep 17 00:00:00 2001 From: Kristofer Hallin Date: Fri, 17 Dec 2021 10:18:42 +0100 Subject: Only retry the database connection if we get an ConnectionError exception. --- src/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main.py') 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) -- cgit v1.1