class Feedlr::Error

Custom error class for rescuing from all Feedlr errors

Attributes

rate_limit[R]

Public Class Methods

errors() click to toggle source

@return [Hash]

# File lib/feedlr/error.rb, line 20
def errors
  @errors ||=  {
    400 => Feedlr::Error::BadRequest,
    401 => Feedlr::Error::Unauthorized,
    403 => Feedlr::Error::Forbidden,
    404 => Feedlr::Error::NotFound,
    500 => Feedlr::Error::InternalServerError
   }
end
from_response(response) click to toggle source

Create a new error from an HTTP response

@param response [Faraday::Response] @return [Feedlr::Error]

# File lib/feedlr/error.rb, line 13
def from_response(response)
  status_code = response.status.to_i
  message = parse_error(status_code, response.body)
  new(message, response.headers)
end
new(message = '', rate_limit = {}) click to toggle source

Initializes a new Error object

@param message [Exception, String] @param rate_limit [Hash] @return [Feedlr::Error]

Calls superclass method
# File lib/feedlr/error.rb, line 50
def initialize(message = '', rate_limit =  {})
  super(message)
  @rate_limit = Feedlr::RateLimit.new(rate_limit)
end

Private Class Methods

parse_error(status, body) click to toggle source
# File lib/feedlr/error.rb, line 32
def parse_error(status, body)
  if body.is_a?(Hash)
    if body['errorMessage']
      "Error #{status} - #{body['errorMessage']}"
    else
      "Error #{status}"
    end
  else
    "Error #{status} - #{body}"
  end
end