Class: Smplkit::ApiErrorDetail

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = meta || {}
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



14
15
16
# File 'lib/smplkit/errors.rb', line 14

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



14
15
16
# File 'lib/smplkit/errors.rb', line 14

def detail
  @detail
end

#metaObject (readonly)

Returns the value of attribute meta.



14
15
16
# File 'lib/smplkit/errors.rb', line 14

def meta
  @meta
end

#sourceObject (readonly)

Returns the value of attribute source.



14
15
16
# File 'lib/smplkit/errors.rb', line 14

def source
  @source
end

#statusObject (readonly)

Returns the value of attribute status.



14
15
16
# File 'lib/smplkit/errors.rb', line 14

def status
  @status
end

#titleObject (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_hObject



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