improve error handling
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from beanie import init_beanie
|
||||
from pymongo import AsyncMongoClient
|
||||
from pymongo.asynchronous.collection import AsyncCollection
|
||||
from pymongo.errors import ServerSelectionTimeoutError, OperationFailure
|
||||
|
||||
from elm.types import User, Transaction, Ticket, Seat, CateringTypes
|
||||
from elm.types.ConfigurationTypes import DatabaseConfiguration
|
||||
@@ -30,6 +32,15 @@ class DatabaseService:
|
||||
if self._client is None:
|
||||
self._client = AsyncMongoClient(mongo_uri)
|
||||
|
||||
try:
|
||||
await self._client.admin.command("ping")
|
||||
except ServerSelectionTimeoutError:
|
||||
print("Could not connect to mongodb")
|
||||
sys.exit(1)
|
||||
except OperationFailure:
|
||||
print("Authentication with mongodb failed")
|
||||
sys.exit(1)
|
||||
|
||||
self._database = self._client[
|
||||
self._db_config.database_name
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user