Exception: FirebaseCloudMessenger::Error

Inherits:
BaseError
  • 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.



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

def initialize(response = nil)
  @response = response

  super(error_message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



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

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



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

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

#parsed_responseObject



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

def parsed_response
  JSON.parse(response_body)
end

#response_bodyObject



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

def response_body
  response.body
end

#response_statusObject



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

def response_status
  response.code.to_i
end

#short_messageObject



44
45
46
# File 'lib/firebase_cloud_messenger/error.rb', line 44

def short_message
  parsed_response["error"]["message"]
end