Exception: SendLayer::SendLayerError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/sendlayer/exceptions.rb

Overview

Base error for the SendLayer SDK.

Every SendLayer error carries the same attributes, so callers can read them without first checking which subclass they rescued:

  • status_code HTTP status of the response, or nil for local errors
  • response decoded response body, or {} when unavailable
  • errors raw SendLayer Errors entries, each with the API's numeric Code and Message; empty for local errors and for responses that aren't in that shape

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', status_code = nil, response = nil, errors = nil) ⇒ SendLayerError

Returns a new instance of SendLayerError.



15
16
17
18
19
20
# File 'lib/sendlayer/exceptions.rb', line 15

def initialize(message = '', status_code = nil, response = nil, errors = nil)
  @status_code = status_code
  @response = response.nil? ? {} : response
  @errors = errors.nil? ? [] : errors
  super(message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/sendlayer/exceptions.rb', line 13

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/sendlayer/exceptions.rb', line 13

def response
  @response
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



13
14
15
# File 'lib/sendlayer/exceptions.rb', line 13

def status_code
  @status_code
end

Instance Method Details

#codesObject

Numeric SendLayer error codes carried by this error, for branching: if err.codes.include?(14).

See https://developers.sendlayer.com/api-reference/error-codes



26
27
28
# File 'lib/sendlayer/exceptions.rb', line 26

def codes
  @errors.filter_map { |entry| entry['Code'] if entry.is_a?(Hash) && entry.key?('Code') }
end