Exception: SimpleFCM::APIError
- Defined in:
- lib/simple_fcm/error.rb
Overview
API errors are raised when there is an issue making a request to the Firebase Cloud Messaging API.
Direct Known Subclasses
InternalServerError, InvalidArgumentError, QuotaExceededError, SenderMismatchError, ServiceUnavailableError, ThirdPartyAuthenticationError, UnregisteredError
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.exception(response) ⇒ Object
exception is called instead of ‘new` when using the form: raise SimpleFCM::APIError, response.
Instance Method Summary collapse
-
#initialize(response) ⇒ APIError
constructor
A new instance of APIError.
- #retriable? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ APIError
Returns a new instance of APIError.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simple_fcm/error.rb', line 16 def initialize(response) if response.body.is_a?(String) @code = response.status super("FCM returned #{response.status}: #{response.body}") else payload = response.body[:error] @code = payload[:code] @status = payload[:status] @details = payload[:details] super(payload[:message]) end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
12 13 14 |
# File 'lib/simple_fcm/error.rb', line 12 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
14 15 16 |
# File 'lib/simple_fcm/error.rb', line 14 def details @details end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/simple_fcm/error.rb', line 13 def status @status end |
Class Method Details
.exception(response) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/simple_fcm/error.rb', line 40 def self.exception(response) klass = case response.status when 400 then InvalidArgumentError when 401 then ThirdPartyAuthenticationError when 403 then SenderMismatchError when 404 then UnregisteredError when 429 then QuotaExceededError when 500 then InternalServerError when 503 then ServiceUnavailableError else APIError end klass.new(response) end |
Instance Method Details
#retriable? ⇒ Boolean
32 33 34 |
# File 'lib/simple_fcm/error.rb', line 32 def retriable? true end |