Exception: HatiJsonapiError::BaseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/hati_jsonapi_error/api_error/base_error.rb

Overview

This is the base error class for all errors in the HatiJsonapiError gem.

Constant Summary collapse

STR =
''
OBJ =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ BaseError

Returns a new instance of BaseError.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 11

def initialize(**attrs)
  @id     = attrs[:id]     || STR
  @code   = attrs[:code]   || STR
  @title  = attrs[:title]  || STR
  @detail = attrs[:detail] || STR
  @status = attrs[:status] || STR

  @links  = build_links(attrs[:links])
  @source = build_source(attrs[:source])
  @meta   = attrs[:meta] || OBJ

  super(error_message)
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def code
  @code
end

#detailObject

Returns the value of attribute detail.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def detail
  @detail
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def id
  @id
end

Returns the value of attribute links.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def links
  @links
end

#metaObject

Returns the value of attribute meta.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def meta
  @meta
end

#sourceObject

Returns the value of attribute source.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def source
  @source
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def status
  @status
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 9

def title
  @title
end

Instance Method Details

#serializable_hashObject



43
44
45
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 43

def serializable_hash
  to_h
end

#to_hObject

NOTE: used in lib/hati_jsonapi_error/payload_adapter.rb



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 26

def to_h
  {
    id: id,
    links: links.to_h,
    status: status,
    code: code,
    title: title,
    detail: detail,
    source: source.to_h,
    meta: meta
  }
end

#to_json(*_args) ⇒ Object



47
48
49
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 47

def to_json(*_args)
  serializable_hash.to_json
end

#to_sObject



39
40
41
# File 'lib/hati_jsonapi_error/api_error/base_error.rb', line 39

def to_s
  to_h.to_s
end