class Mongo::Auth::Unauthorized

Raised when a user is not authorized on a database.

@since 2.0.0

Public Class Methods

new(user, used_mechanism = nil) click to toggle source

Instantiate the new error.

@example Instantiate the error.

Mongo::Auth::Unauthorized.new(user)

@param [ Mongo::Auth::User ] user The unauthorized user. @param [ String ] used_mechanism Auth mechanism actually used for

authentication. This is a full string like SCRAM-SHA-256

@since 2.0.0

Calls superclass method
# File lib/mongo/auth.rb, line 109
def initialize(user, used_mechanism = nil)
  specified_mechanism = if user.mechanism
    " (mechanism: #{user.mechanism})"
  else
    ''
  end
  used_mechanism = if used_mechanism
    " (used mechanism: #{used_mechanism})"
  else
    ''
  end
  msg = "User #{user.name}#{specified_mechanism} is not authorized to access #{user.database}#{used_mechanism}"
  super(msg)
end