Exception: MisarMail::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/misar_mail/errors.rb

Direct Known Subclasses

NetworkError, PlanLimitError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, message, error_type = "api_error") ⇒ ApiError

Returns a new instance of ApiError.



5
6
7
8
9
# File 'lib/misar_mail/errors.rb', line 5

def initialize(status, message, error_type = "api_error")
  @status = status
  @error_type = error_type
  super("misar-mail: API error #{status} (#{error_type}): #{message}")
end

Instance Attribute Details

#error_typeObject (readonly)

Returns the value of attribute error_type.



3
4
5
# File 'lib/misar_mail/errors.rb', line 3

def error_type
  @error_type
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/misar_mail/errors.rb', line 3

def status
  @status
end

Class Method Details

.from_response(response) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/misar_mail/errors.rb', line 11

def self.from_response(response)
  body = begin
    JSON.parse(response.body)
  rescue StandardError
    {}
  end
  new(response.status, body["error"] || response.reason_phrase || "unknown error")
end