Class: Railsmith::Errors::ErrorPayload
- Inherits:
-
Object
- Object
- Railsmith::Errors::ErrorPayload
- Defined in:
- lib/railsmith/errors.rb
Overview
A structured error payload used in failure results.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(code:, message:, details: nil) ⇒ ErrorPayload
constructor
A new instance of ErrorPayload.
- #to_h ⇒ Object
Constructor Details
#initialize(code:, message:, details: nil) ⇒ ErrorPayload
Returns a new instance of ErrorPayload.
10 11 12 13 14 15 |
# File 'lib/railsmith/errors.rb', line 10 def initialize(code:, message:, details: nil) @code = code.to_s @message = .to_s @details = details freeze end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/railsmith/errors.rb', line 8 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
8 9 10 |
# File 'lib/railsmith/errors.rb', line 8 def details @details end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/railsmith/errors.rb', line 8 def @message end |
Instance Method Details
#as_json ⇒ Object
23 24 25 |
# File 'lib/railsmith/errors.rb', line 23 def as_json(*) to_h end |
#to_h ⇒ Object
17 18 19 20 21 |
# File 'lib/railsmith/errors.rb', line 17 def to_h payload = { code:, message: } payload[:details] = details unless details.nil? payload end |