Exception: Observable::StructuredError
- Inherits:
-
StandardError
- Object
- StandardError
- Observable::StructuredError
- Defined in:
- lib/observable/structured_error.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, type: self.class.name, context: {}) ⇒ StructuredError
constructor
A new instance of StructuredError.
- #inspect ⇒ Object
- #pretty_print ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(message, type: self.class.name, context: {}) ⇒ StructuredError
Returns a new instance of StructuredError.
7 8 9 10 11 |
# File 'lib/observable/structured_error.rb', line 7 def initialize(, type: self.class.name, context: {}) @context = context.to_h @type = (type || self.class.name).to_s super() end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/observable/structured_error.rb', line 5 def context @context end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/observable/structured_error.rb', line 5 def type @type end |
Class Method Details
.from_error(error) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/observable/structured_error.rb', line 25 def self.from_error(error) custom_converter_result = try_custom_converter(error) if custom_converter_result new( custom_converter_result[:message], type: custom_converter_result[:type], context: custom_converter_result[:context] ) else new( (error), type: safe_type(error), context: safe_context(error) ) end end |
Instance Method Details
#inspect ⇒ Object
17 18 19 |
# File 'lib/observable/structured_error.rb', line 17 def inspect "#<#{self.class.name}: #{message}, type=#{type}, context=#{@context}>" end |
#pretty_print ⇒ Object
21 22 23 |
# File 'lib/observable/structured_error.rb', line 21 def pretty_print "#<#{self.class.name}: message: #{message}, type: #{type}, context: #{@context}>" end |
#to_h ⇒ Object
13 14 15 |
# File 'lib/observable/structured_error.rb', line 13 def to_h {message: }.merge(@context) end |