class Cuprum::Error
Wrapper class for encapsulating an error state for a failed Cuprum
result.
Additional details can be passed by setting the message
or by using a subclass of Cuprum::Error
.
Constants
- TYPE
Short string used to identify the type of error.
Primarily used for serialization. This value can be overriden by passing in the :type parameter to the constructor.
Subclasses of
Cuprum::Error
should define their own defaultTYPE
constant.
Attributes
@return [String] optional message describing the nature of the error.
@return [String] short string used to identify the type of error.
Public Class Methods
@param message [String] Optional message describing the nature of the
error.
@param properties [Hash] Additional properties used to compare errors. @param type [String] Short string used to identify the type of error.
# File lib/cuprum/error.rb, line 23 def initialize(message: nil, type: nil, **properties) @message = message @type = type || self.class::TYPE @comparable_properties = properties.merge(message: message, type: type) end
Public Instance Methods
@param other [Cuprum::Error] The other object to compare.
@return [Boolean] true if the other object has the same class and
properties; otherwise false.
# File lib/cuprum/error.rb, line 39 def ==(other) other.instance_of?(self.class) && other.comparable_properties == comparable_properties end
Generates a serializable representation of the error object.
By default, contains the type
and message
properties and an empty :data Hash. This can be overriden in subclasses by overriding the private method as_json_data
; this should always return a Hash with String keys and whose values are basic objects or data structures of the same.
@return [Hash<String, Object>] a serializable hash representation of the
error.
# File lib/cuprum/error.rb, line 53 def as_json { 'data' => as_json_data, 'message' => message, 'type' => type } end
Private Instance Methods
# File lib/cuprum/error.rb, line 67 def as_json_data {} end