Exception: RpiUnion::ApiError

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

Constant Summary collapse

ERROR_TYPES =
{
  2 => "Task Not Found",
  3 => "Database Error",
  4 => "Invalid API Key",
  5 => "Unauthorized Origin",
  10 => "Validation Error",
  11 => "Data Not Found",
}

Instance Method Summary collapse

Constructor Details

#initialize(status_obj) ⇒ ApiError

Returns a new instance of ApiError.



99
100
101
102
# File 'lib/rpi_union.rb', line 99

def initialize(status_obj)
  @code = status_obj['code']
  @text = status_obj['text']
end

Instance Method Details

#get_error_type(code) ⇒ Object



104
105
106
107
# File 'lib/rpi_union.rb', line 104

def get_error_type(code)
  return "API Error" unless ERROR_TYPES.key?(code)
  ERROR_TYPES[code]
end

#messageObject



109
110
111
# File 'lib/rpi_union.rb', line 109

def message
  return "#{get_error_type(@code)}: #{@text}"
end