Exception: Mongo::Auth::Unauthorized
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Mongo::Error::AuthError ,
RuntimeError
|
|
Instance Chain:
|
|
Inherits: |
Mongo::Error::AuthError
|
Defined in: | lib/mongo/auth.rb |
Overview
Raised when a user is not authorized on a database.
Constant Summary
::Mongo::Error::ReadWriteRetryable
- Included
Class Method Summary
-
.new(user, used_mechanism: nil, message: nil, server: nil, code: nil) ⇒ Unauthorized
constructor
Instantiate the new error.
Instance Attribute Summary
- #code ⇒ Integer readonly
::Mongo::Error::ReadWriteRetryable
- Included
#retryable? | Whether the error is a retryable error according to the legacy read retry logic. |
#write_retryable? | Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications. |
#write_retryable_code? |
::Mongo::Error::Notable
- Included
#connection_global_id | Returns global id of the connection on which the error occurred. |
#generation | Returns connection pool generation for the connection on which the error occurred. |
#service_id | Returns service id for the connection on which the error occurred. |
Instance Method Summary
::Mongo::Error::Labelable
- Included
#add_label | Adds the specified label to the error instance, if the label is not already in the set of labels. |
#label? | Does the error have the given label? |
#labels | Gets the set of labels associated with the error. |
::Mongo::Error::Notable
- Included
#add_note, | |
#add_notes | Allows multiple notes to be added in a single call, for convenience. |
#notes | Returns an array of strings with additional information about the exception. |
#to_s, #notes_tail |
Constructor Details
.new(user, used_mechanism: nil, message: nil, server: nil, code: nil) ⇒ Unauthorized
Instantiate the new error.
# File 'lib/mongo/auth.rb', line 153
def initialize(user, used_mechanism: nil, message: nil, server: nil, code: nil ) @code = code configured_bits = [] used_bits = [ "auth source: #{user.auth_source}", ] if user.mechanism configured_bits << "mechanism: #{user.mechanism}" end if used_mechanism used_bits << "used mechanism: #{used_mechanism}" end if server used_bits << "used server: #{server.address} (#{server.status})" end used_user = if user.mechanism == :mongodb_x509 'Client certificate' else "User #{user.name}" end if configured_bits.empty? configured_bits = '' else configured_bits = " (#{configured_bits.join(', ')})" end used_bits = " (#{used_bits.join(', ')})" msg = "#{used_user}#{configured_bits} is not authorized to access #{user.database}#{used_bits}" if msg += ': ' + end super(msg) end
Instance Attribute Details
#code ⇒ Integer
(readonly)
# File 'lib/mongo/auth.rb', line 137
attr_reader :code