Generic error class for exceptions generated on the remote MongoDB server.
@attribute [r] details The details about the error. @attribute [r] command The command that generated the error.
@attribute [r] details The details about the error. @attribute [r] command The command that generated the error.
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
# File lib/moped/errors.rb, line 50 def initialize(command, details) @command, @details = command, details super(build_message) end
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
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