Class: Smplkit::ApiErrorDetail
- Inherits:
-
Object
- Object
- Smplkit::ApiErrorDetail
- Defined in:
- lib/smplkit/errors.rb
Overview
A single error object from the server’s JSON:API errors array.
code is the application-specific machine-readable error code (e.g. environment_unmanaged); per JSON:API §7 and ADR-014, smplkit sets this on every error so callers can branch without string-matching the human detail. meta carries additional structured context (e.g. {"environment" => "staging"}).
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(status: nil, code: nil, title: nil, detail: nil, source: nil, meta: nil) ⇒ ApiErrorDetail
constructor
A new instance of ApiErrorDetail.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(status: nil, code: nil, title: nil, detail: nil, source: nil, meta: nil) ⇒ ApiErrorDetail
Returns a new instance of ApiErrorDetail.
16 17 18 19 20 21 22 23 |
# File 'lib/smplkit/errors.rb', line 16 def initialize(status: nil, code: nil, title: nil, detail: nil, source: nil, meta: nil) @status = status @code = code @title = title @detail = detail @source = source || {} @meta = || {} end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def code @code end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def detail @detail end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def @meta end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def source @source end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def status @status end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/smplkit/errors.rb', line 14 def title @title end |
Instance Method Details
#to_h ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/smplkit/errors.rb', line 25 def to_h h = {} h["status"] = @status unless @status.nil? h["code"] = @code unless @code.nil? h["title"] = @title unless @title.nil? h["detail"] = @detail unless @detail.nil? h["source"] = @source unless @source.empty? h["meta"] = @meta unless @meta.empty? h end |
#to_json(*args) ⇒ Object
36 37 38 |
# File 'lib/smplkit/errors.rb', line 36 def to_json(*args) JSON.generate(to_h, *args) end |