Exception: AmazonAds::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/amazon_ads/error.rb

Overview

Raised when the API or LWA responds with a 4xx or 5xx

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, response = nil) ⇒ Error

Returns a new instance of Error.

Signature:

  • (?String?, ?HTTP::Response?) -> void



18
19
20
21
# File 'lib/amazon_ads/error.rb', line 18

def initialize(msg = nil, response = nil)
  @response = response
  super(msg)
end

Instance Attribute Details

#responseObject (readonly)

The failed response



9
10
11
# File 'lib/amazon_ads/error.rb', line 9

def response
  @response
end

Class Method Details

.build(response) ⇒ Object

Signature:

  • (HTTP::Response) -> Error



12
13
14
15
# File 'lib/amazon_ads/error.rb', line 12

def self.build(response)
  response.flush # memoize the body while the connection is still readable
  new(response.status.to_s, response)
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object

Supports pattern matching on status

case error
in status: 429 then backoff
in status: 500..599 then retry
end

Signature:

  • (Array[Symbol]?) -> Hash[Symbol, untyped]



36
37
38
39
# File 'lib/amazon_ads/error.rb', line 36

def deconstruct_keys(keys)
  hash = { status: status }
  keys ? hash.slice(*keys) : hash
end

#statusObject

Signature:

  • () -> Integer?



24
25
26
# File 'lib/amazon_ads/error.rb', line 24

def status
  response&.status&.code
end