Exception: FirebaseCloudMessenger::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/firebase_cloud_messenger/error.rb

Direct Known Subclasses

BadRequest, Forbidden, NotFound, Unauthorized

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Error

Returns a new instance of Error.



21
22
23
24
25
# File 'lib/firebase_cloud_messenger/error.rb', line 21

def initialize(response = nil)
  @response = response

  super(error_message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/firebase_cloud_messenger/error.rb', line 5

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/firebase_cloud_messenger/error.rb', line 7

def self.from_response(response)
  status = response.code

  klass = case status.to_i
          when 400 then FirebaseCloudMessenger::BadRequest
          when 401 then FirebaseCloudMessenger::Unauthorized
          when 403 then FirebaseCloudMessenger::Forbidden
          when 404 then FirebaseCloudMessenger::NotFound
          else self
          end

  klass.new(response)
end

Instance Method Details

#detailsObject



39
40
41
# File 'lib/firebase_cloud_messenger/error.rb', line 39

def details
  parsed_response["error"]["details"]
end

#parsed_responseObject



35
36
37
# File 'lib/firebase_cloud_messenger/error.rb', line 35

def parsed_response
  JSON.parse(response_body)
end

#response_bodyObject



31
32
33
# File 'lib/firebase_cloud_messenger/error.rb', line 31

def response_body
  response.body
end

#response_statusObject



27
28
29
# File 'lib/firebase_cloud_messenger/error.rb', line 27

def response_status
  response.code.to_i
end