Exception: AhoSdk::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/aho_sdk/http_client.rb

Overview

Base error class for API errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, status_code, request_id = nil) ⇒ ApiError

Returns a new instance of ApiError.



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/aho_sdk/http_client.rb', line 334

def initialize(body, status_code, request_id = nil)
  @status_code = status_code
  @request_id = request_id
  @raw_body = body

  begin
    parsed = JSON.parse(body, symbolize_names: true)
    error = parsed[:error] || parsed
    @error_code = error[:code]
    @details = normalize_details(error[:details])
    super(error[:message] || body)
  rescue JSON::ParserError
    @error_code = "unknown"
    @details = []
    super(body)
  end
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



332
333
334
# File 'lib/aho_sdk/http_client.rb', line 332

def details
  @details
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



332
333
334
# File 'lib/aho_sdk/http_client.rb', line 332

def error_code
  @error_code
end

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



332
333
334
# File 'lib/aho_sdk/http_client.rb', line 332

def raw_body
  @raw_body
end

#request_idObject (readonly)

Returns the value of attribute request_id.



332
333
334
# File 'lib/aho_sdk/http_client.rb', line 332

def request_id
  @request_id
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



332
333
334
# File 'lib/aho_sdk/http_client.rb', line 332

def status_code
  @status_code
end