Exception: MailerLite::Error
- Inherits:
-
StandardError
- Object
- StandardError
- MailerLite::Error
- Defined in:
- lib/mailerlite/error.rb
Overview
Base MailerLite error.
Direct Known Subclasses
BadRequest, InternalServerError, NotFound, TooManyRequests, Unauthorized
Class Method Summary collapse
- .error_class(status) ⇒ Object
-
.error_message(response) ⇒ String
Returns the appropriate MailerLite error message based on response.
-
.from_response(response) ⇒ MailerLite::Error
Returns the appropriate MailerLite::Error sublcass based on status and response message.
Instance Method Summary collapse
-
#initialize(msg = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(msg = nil) ⇒ Error
Returns a new instance of Error.
6 7 8 |
# File 'lib/mailerlite/error.rb', line 6 def initialize(msg = nil) @message = msg end |
Class Method Details
.error_class(status) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/mailerlite/error.rb', line 24 def self.error_class(status) case status when 400 then MailerLite::BadRequest when 401 then MailerLite::Unauthorized when 404 then MailerLite::NotFound when 429 then MailerLite::TooManyRequests when 500 then MailerLite::InternalServerError end end |
.error_message(response) ⇒ String
Returns the appropriate MailerLite error message based on response
39 40 41 42 43 44 45 |
# File 'lib/mailerlite/error.rb', line 39 def self.(response) return unless response.body.is_a?(Hash) return unless response.body['error'] = response.body['error']['message'] MailerLite::Utils.presence() end |
.from_response(response) ⇒ MailerLite::Error
Returns the appropriate MailerLite::Error sublcass based on status and response message.
16 17 18 19 20 21 22 |
# File 'lib/mailerlite/error.rb', line 16 def self.from_response(response) status = response.status.to_i = (response) klass = error_class(status) klass&.new() end |