Add a new exception for MongoDB Authentication errors

This commit is contained in:
Lavina 2017-03-29 17:10:55 +05:30
parent 0edb1c18f2
commit 9c4b284db9
2 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,10 @@ class ConnectionError(BackendError):
"""Exception raised when the connection to the backend fails.""" """Exception raised when the connection to the backend fails."""
class AuthenticationError(ConnectionError):
"""Exception raised when MongoDB Authentication fails"""
class OperationError(BackendError): class OperationError(BackendError):
"""Exception raised when a backend operation fails.""" """Exception raised when a backend operation fails."""

View File

@ -8,7 +8,8 @@ from bigchaindb.utils import Lazy
from bigchaindb.common.exceptions import ConfigurationError from bigchaindb.common.exceptions import ConfigurationError
from bigchaindb.backend.exceptions import (DuplicateKeyError, from bigchaindb.backend.exceptions import (DuplicateKeyError,
OperationError, OperationError,
ConnectionError) ConnectionError,
AuthenticationError)
from bigchaindb.backend.connection import Connection from bigchaindb.backend.connection import Connection
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -83,6 +84,8 @@ class MongoDBConnection(Connection):
# `initialize_replica_set` might raise `ConnectionFailure` or `OperationFailure`. # `initialize_replica_set` might raise `ConnectionFailure` or `OperationFailure`.
except (pymongo.errors.ConnectionFailure, except (pymongo.errors.ConnectionFailure,
pymongo.errors.OperationFailure) as exc: pymongo.errors.OperationFailure) as exc:
if "Authentication fail" in str(exc):
raise AuthenticationError() from exc
raise ConnectionError() from exc raise ConnectionError() from exc