Exception: RpiUnion::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- RpiUnion::ApiError
- 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
- #get_error_type(code) ⇒ Object
-
#initialize(status_obj) ⇒ ApiError
constructor
A new instance of ApiError.
- #message ⇒ Object
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 |
#message ⇒ Object
109 110 111 |
# File 'lib/rpi_union.rb', line 109 def return "#{get_error_type(@code)}: #{@text}" end |