Exception: Latitude::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/latitude/api/errors.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, http_status: nil, http_headers: nil, http_body: nil, json_body: nil, request_id: nil) ⇒ APIError

Returns a new instance of APIError.



44
45
46
47
48
49
50
51
52
# File 'lib/latitude/api/errors.rb', line 44

def initialize(message = nil, http_status: nil, http_headers: nil, http_body: nil, json_body: nil, request_id: nil)
  @http_status  = http_status
  @http_headers = http_headers || {}
  @http_body    = http_body
  @json_body    = json_body
  @request_id   = request_id
  @entries      = Array(json_body.is_a?(Hash) ? json_body["errors"] : nil).map { |h| Entry.new(h) }
  super(message || default_message)
end

Instance Attribute Details

#entriesObject (readonly) Also known as: errors

Returns the value of attribute entries.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def entries
  @entries
end

#http_bodyObject (readonly)

Returns the value of attribute http_body.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def http_body
  @http_body
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def http_headers
  @http_headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def http_status
  @http_status
end

#json_bodyObject (readonly)

Returns the value of attribute json_body.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def json_body
  @json_body
end

#request_idObject (readonly)

Returns the value of attribute request_id.



42
43
44
# File 'lib/latitude/api/errors.rb', line 42

def request_id
  @request_id
end

Instance Method Details

#codeObject



56
57
58
# File 'lib/latitude/api/errors.rb', line 56

def code
  entries.first&.code
end

#detailObject



64
65
66
# File 'lib/latitude/api/errors.rb', line 64

def detail
  entries.first&.detail
end

#titleObject



60
61
62
# File 'lib/latitude/api/errors.rb', line 60

def title
  entries.first&.title
end