Exception: Lieu::Error

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

Overview

Custom error class

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Lieu::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
30
31
32
33
34
35
36
37
38
# File 'lib/lieu/error.rb', line 10

def self.from_response(response)
  content_type = response[:response_headers]['content-type']

  status =
    if content_type =~ /json/
      ::MultiJson.load(response[:body])['status']
    else
      response[:status]
    end

  case status
  when 'INVALID_REQUEST'
    raise Lieu::InvalidRequest, status
  when 'REQUEST_DENIED'
    raise Lieu::RequestDenied, status
  when 'NOT_FOUND'
    raise Lieu::NotFound, status
  when 'UNKNOWN_ERROR'
    raise Lieu::UnknownError, status
  when 'ZERO_RESULTS'
    raise Lieu::ZeroResults, status
  when 'OVER_QUERY_LIMIT'
    raise Lieu::OverQueryLimit, status
  when 400
    raise Lieu::InvalidRequest, status
  when 403
    raise Lieu::OverQueryLimit, status
  end
end