Exception: Mailgun::CommunicationError
- Defined in:
- lib/mailgun/exceptions/exceptions.rb
Overview
Public: Class for managing communications (eg http) response errors Inherits from Mailgun::Error
Constant Summary collapse
- NOCODE =
Public: fallback if there is no response code on the object
000
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Public: gets HTTP status code.
Attributes inherited from Error
Instance Method Summary collapse
-
#initialize(message = nil, response = nil) ⇒ CommunicationError
constructor
Public: initialization of new error given a message and/or object.
Constructor Details
#initialize(message = nil, response = nil) ⇒ CommunicationError
Public: initialization of new error given a message and/or object
message - a String detailing the error response - a RestClient::Response object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mailgun/exceptions/exceptions.rb', line 43 def initialize( = nil, response = nil) @response = response @code = response.code || NOCODE begin = JSON.parse(response.body)['message'] rescue JSON::ParserError = response.body rescue NoMethodError = "Unknown API error" end = || '' = + ': ' + super(, response) rescue NoMethodError, JSON::ParserError @code = NOCODE super(, response) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Public: gets HTTP status code
33 34 35 |
# File 'lib/mailgun/exceptions/exceptions.rb', line 33 def code @code end |