Exception: EasyPing::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/easy_ping/error.rb

Overview

Wrap error responded from server side

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#inspect

Constructor Details

#initialize(response) ⇒ APIError

Returns a new instance of APIError.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/easy_ping/error.rb', line 27

def initialize(response)
  @status  = response.status
  @error   = JSON.parse(response.body)['error'] rescue {}
  @type    = @error['type']
  @code    = @error['code']
  @param   = @error['param']
  @message = @error['message']

  message =  "Server responded with status #{@status}."
  message += " Full Message: #{@message}." if @message
  super(message)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



26
27
28
# File 'lib/easy_ping/error.rb', line 26

def code
  @code
end

#paramObject (readonly)

Returns the value of attribute param.



26
27
28
# File 'lib/easy_ping/error.rb', line 26

def param
  @param
end

#statusObject (readonly)

Returns the value of attribute status.



26
27
28
# File 'lib/easy_ping/error.rb', line 26

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



26
27
28
# File 'lib/easy_ping/error.rb', line 26

def type
  @type
end