Exception: GrowthPush::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
lib/growth_push/exception.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, code, message) ⇒ Exception

Returns a new instance of Exception.



29
30
31
32
33
# File 'lib/growth_push/exception.rb', line 29

def initialize(status, code, message)
  @status = status
  @code   = code
  super message
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/growth_push/exception.rb', line 3

def code
  @code
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/growth_push/exception.rb', line 3

def status
  @status
end

Class Method Details

.handle_response(response) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/growth_push/exception.rb', line 6

def handle_response(response)
  klass = klass_for_status(response.code.to_i)
  exception = if klass
                klass.new(response.code, response.message)
              else
                Exception.new(response.code.to_i, response.code, response.message)
              end
end

.klass_for_status(status) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/growth_push/exception.rb', line 15

def klass_for_status(status)
  case status
  when 400
    BadRequest
  when 401
    Unauthorized
  when 404
    NotFound
  when 500
    InternalServerError
  end
end