Exception: MisarMail::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- MisarMail::ApiError
- Defined in:
- lib/misar_mail/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_type ⇒ Object
readonly
Returns the value of attribute error_type.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status, message, error_type = "api_error") ⇒ ApiError
constructor
A new instance of ApiError.
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, , error_type = "api_error") @status = status @error_type = error_type super("misar-mail: API error #{status} (#{error_type}): #{}") end |
Instance Attribute Details
#error_type ⇒ Object (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 |
#status ⇒ Object (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 |