code: def mongodb_exception_wrapper(method):
      """Convert pymongo exceptions to generic exception types defined in src.core.io.database.
  
      Current exception types converted:
      pymongo.errors.DuplicateKeyError -> DuplicateKeyError
      pymongo.errors.BulkWriteError[DUPLICATE_KEY_MESSAGES] -> DuplicateKeyError
      pymongo.errors.ConnectionFailure -> DatabaseError
      pymongo.errors.OperationFailure(AUTH_FAILED_MESSAGES) -> DatabaseError
  
      """
  
      @functools.wraps(method)
      def _decorator(self, *args, **kwargs):
          try:
              rval = method(self, *args, **kwargs)
          except pymongo.errors.ExecutionTimeout as e:
              # Raised when a database operation times out, exceeding the $maxTimeMS set in
              # the query or command option.
              raise DatabaseTimeout() from e
          except pymongo.errors.NetworkTimeout as e:
              # An operation on an open connection exceeded socketTimeoutMS.
              #
              # The remaining connections in the pool stay open. In the case of a
              # write operation, you cannot know whether it succeeded or failed.
              raise DatabaseTimeout() from e
          except pymongo.errors.WTimeoutError as e:
              # Raised when a database operation times out (i.e. wtimeout expires)
              # before replication completes.
              raise DatabaseTimeout() from e
          except pymongo.errors.DuplicateKeyError as e:
              raise DuplicateKeyError(str(e)) from e
          except pymongo.errors.BulkWriteError as e:
              for error in e.details["writeErrors"]:
                  if any(
                      m in error["errmsg"]
                      for m in DUPLICATE_KEY_MESSAGES
                  ):
                      raise DuplicateKeyError(error["errmsg"]) from e
  
              raise
          except pymongo.errors.ConnectionFailure as e:
              raise DatabaseError(
                  "Connection Failure: database not found on specified uri"
              ) from e
          except pymongo.errors.OperationFailure as e:
              if any(m in str(e) for m in AUTH_FAILED_MESSAGES):
                  raise DatabaseError(
                      "Authentication Failure: bad credentials"
                  ) from e
              elif any(m in str(e) for m in INDEX_OP_ERROR_MESSAGES):
                  raise DatabaseError(str(e)) from e
              raise
  
          return rval
  
      return _decorator
  
imports: import functools
  import pymongo
  from orion.core.io.database import Database, DatabaseError, DatabaseTimeout, DuplicateKeyError
label_desc: Use image node_id 1 for calling a global function with example usage: mongodb_exception_wrapper(method) and returns: _decorator, rval