Exception: SimpleFCM::APIError

Inherits:
Error
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



12
13
14
# File 'lib/simple_fcm/error.rb', line 12

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



14
15
16
# File 'lib/simple_fcm/error.rb', line 14

def details
  @details
end

#statusObject (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

exception is called instead of ‘new` when using the form:

raise SimpleFCM::APIError, response

Parameters:

  • response (Faraday::Response)


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

Returns:

  • (Boolean)


32
33
34
# File 'lib/simple_fcm/error.rb', line 32

def retriable?
  true
end