Exception: Usps::Imis::Errors::ResponseError

Inherits:
Usps::Imis::Error show all
Defined in:
lib/usps/imis/errors/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(response, metadata = {}) ⇒ ResponseError

Create a new instance of ResponseError

Parameters:

  • response (Net::HTTPResponse)

    The response received from the API

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

    Additional call-specific metadata to pass through to Bugsnag



28
29
30
31
# File 'lib/usps/imis/errors/response_error.rb', line 28

def initialize(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/errors/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/errors/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
# File 'lib/usps/imis/errors/response_error.rb', line 21

def self.from(response) = new(response)

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:

  • (Hash)


42
43
44
# File 'lib/usps/imis/errors/response_error.rb', line 42

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

#messageString

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

Returns:

  • (String)

    The exception message



50
51
52
53
54
55
56
# File 'lib/usps/imis/errors/response_error.rb', line 50

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