Exception: Gistance::Error

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

Overview

Custom error class

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Gistance::Error

Returns the Error based on status and response message.

Parameters:

  • response (Hash)

    HTTP response

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gistance/error.rb', line 10

def self.from_response(response)
  status = ::MultiJson.load(response[:body])['status']

  case status
  when 'INVALID_REQUEST'
    raise Gistance::InvalidRequest, status
  when 'MAX_ELEMENTS_EXCEEDED'
    raise Gistance::MaxElementsExceeded, status
  when 'OVER_QUERY_LIMIT'
    raise Gistance::OverQueryLimit, status
  when 'REQUEST_DENIED'
    raise Gistance::RequestDenied, status
  when 'UNKNOWN_ERROR'
    raise Gistance::UnknownError, status
  when 'NOT_FOUND'
    raise Gistance::NotFound, status
  when 'ZERO_RESULTS'
    raise Gistance::ZeroResults, status
  end
end