Exception: Mailgun::CommunicationError
- Defined in:
- lib/mailgun/exceptions/exceptions.rb
Overview
Public: Class for managing communications (eg http) response errors Inherits from Mailgun::Error
Direct Known Subclasses
Constant Summary collapse
- NOCODE =
Public: fallback if there is no response status on the object
000- FORBIDDEN =
'Forbidden'
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Public: gets HTTP status status.
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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mailgun/exceptions/exceptions.rb', line 46 def initialize( = nil, response = nil) @response = response @status = if response.nil? NOCODE else response[:status] end begin json = JSON.parse(response[:body]) = json['message'] || json['Error'] || json['error'] rescue JSON::ParserError = response.response_body rescue NoMethodError = "Unknown API error" rescue = 'Unknown API error' end = || '' = + ': ' + ( || "") super(, response) rescue NoMethodError, JSON::ParserError @status = NOCODE super(, response) end |
Instance Attribute Details
#status ⇒ Object (readonly)
Public: gets HTTP status status
35 36 37 |
# File 'lib/mailgun/exceptions/exceptions.rb', line 35 def status @status end |