class Moped::Errors::MongoError
Generic error class for exceptions generated on the remote MongoDB server.
Attributes
command[R]
@attribute [r] details The details about the error. @attribute [r] command The command that generated the error.
details[R]
@attribute [r] details The details about the error. @attribute [r] command The command that generated the error.
Public Class Methods
new(command, details)
click to toggle source
Create a new operation failure exception.
@example Create the new error.
MongoError.new(command, details)
@param [ Object
] command The command that generated the error. @param [ Hash
] details The details about the error.
@since 1.0.0
Calls superclass method
# File lib/moped/errors.rb, line 50 def initialize(command, details) @command, @details = command, details super(build_message) end
Private Instance Methods
build_message()
click to toggle source
Build the error message.
@api private
@example Build the message.
error.build_message
@return [ String
] The message.
@since 1.0.0
# File lib/moped/errors.rb, line 67 def build_message "The operation: #{command.inspect}\n#{error_message}" end
error_message()
click to toggle source
Get the error message.
@api private
@example Get the error message.
error.error_message
@return [ String
] The message.
@since 1.0.0
# File lib/moped/errors.rb, line 81 def error_message err = details["err"] || details["errmsg"] || details["$err"] if code = details["code"] "failed with error #{code}: #{err.inspect}\n\n" << "See #{ERROR_REFERENCE}\nfor details about this error." elsif code = details["assertionCode"] assertion = details["assertion"] "failed with error #{code}: #{assertion.inspect}\n\n" << "See #{ERROR_REFERENCE}\nfor details about this error." else "failed with error #{err.inspect}" end end