Exception: Twingly::Search::Error

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

Direct Known Subclasses

AuthError, QueryError, ServerError

Class Method Summary collapse

Class Method Details

.from_api_response(code, message) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/twingly/search/error.rb', line 6

def self.from_api_response(code, message)
  error =
    case code.to_s
    when /^400/, /^404/
      QueryError
    when /^401/ # E.g. API key not enabled
      AuthenticationError
    when /^402/ # E.g. language access denied
      AuthorizationError
    else
      ServerError
    end

  error.new("#{message} (code: #{code})")
end