Exception: Usps::Imis::Error::ResponseError

Inherits:
ApiError
  • Object
show all
Defined in:
lib/usps/imis/error/response_error.rb

Overview

Exception raised due to receiving an error response from the API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_message, response, metadata = {}) ⇒ ResponseError

Create a new instance of ResponseError

Parameters:

  • _message

    Ignored

  • response (Net::HTTPResponse)

    The response received from the API

  • metadata (Hash) (defaults to: {})

    Additional call-specific metadata to pass through to Bugsnag



31
32
33
34
# File 'lib/usps/imis/error/response_error.rb', line 31

def initialize(_message, response,  = {})
  @response = response
  super(message, )
end

Instance Attribute Details

#metadataObject

Hash

Additional call-specific metadata to pass through to Bugsnag



15
16
17
# File 'lib/usps/imis/error/response_error.rb', line 15

def 
  @metadata
end

#responseObject (readonly)

Net::HTTPResponse

The response received from the API



11
12
13
# File 'lib/usps/imis/error/response_error.rb', line 11

def response
  @response
end

Class Method Details

.from(response) ⇒ Object

Create a new instance of ResponseError from an API response

Parameters:

  • response (Net::HTTPResponse)

    The response received from the API



21
22
23
# File 'lib/usps/imis/error/response_error.rb', line 21

def self.from(response)
  new(nil, response)
end

Instance Method Details

#bugsnag_meta_dataHash

Additional metadata to include in Bugsnag reports

Can include fields at the top level, which will be shows on the custom tab

Can include fields nested under a top-level key, which will be shown on a tab with the top-level key as its name

Returns:



45
46
47
# File 'lib/usps/imis/error/response_error.rb', line 45

def 
  .tap { |m| m[:api].merge!() }
end

#messageString

Auto-formatted exception message, based on the provided API response

Returns:

  • (String)

    The exception message



53
54
55
56
57
58
59
# File 'lib/usps/imis/error/response_error.rb', line 53

def message
  [
    "#{self.class.name}: [#{status.to_s.upcase}] The iMIS API returned an error.",
    (.inspect if  != {}),
    body
  ].compact.join("\n")
end