Exception: FriendlyShipping::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/friendly_shipping/api_error.rb

Overview

Raised when an API error is returned. Parent of carrier-specific API error classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cause, message = nil) ⇒ ApiError

Returns a new instance of ApiError.

Parameters:

  • cause (RestClient::Exception, nil)

    the cause of the error

  • message (String) (defaults to: nil)

    optional descriptive message

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/friendly_shipping/api_error.rb', line 11

def initialize(cause, message = nil)
  raise ArgumentError, "Must provide either a cause or a message" if cause.nil? && message.nil?

  @cause = cause
  super(message || cause&.message)
end

Instance Attribute Details

#causeRestClient::Exception (readonly)

Returns the cause of the error.

Returns:

  • (RestClient::Exception)

    the cause of the error



7
8
9
# File 'lib/friendly_shipping/api_error.rb', line 7

def cause
  @cause
end