Merge pull request #1357 from lavinasachdev3/bug/1336/handle-authentication-exception

Add a new exception for MongoDB Authentication errors
This commit is contained in:
Rodolphe Marques 2017-06-01 10:15:26 +02:00 committed by GitHub
commit b3d72d84e4
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__)
@ -93,6 +94,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