class Twingly::Search::Error

Public Class Methods

from_api_response(code, message) click to toggle source
# 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