Exception: Feedlr::Error

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

Overview

Custom error class for rescuing from all Feedlr errors

Direct Known Subclasses

ClientError, RequestTimeout, ServerError

Defined Under Namespace

Classes: BadRequest, ClientError, Forbidden, InternalServerError, NotFound, RequestTimeout, ServerError, Unauthorized

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', rate_limit = {}) ⇒ Feedlr::Error

Initializes a new Error object

Parameters:

  • message (Exception, String) (defaults to: '')
  • rate_limit (Hash) (defaults to: {})


50
51
52
53
# File 'lib/feedlr/error.rb', line 50

def initialize(message = '', rate_limit =  {})
  super(message)
  @rate_limit = Feedlr::RateLimit.new(rate_limit)
end

Instance Attribute Details

#rate_limitObject (readonly)

Returns the value of attribute rate_limit.



6
7
8
# File 'lib/feedlr/error.rb', line 6

def rate_limit
  @rate_limit
end

Class Method Details

.errorsHash

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
28
# 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) ⇒ Feedlr::Error

Create a new error from an HTTP response

Parameters:

  • response (Faraday::Response)

Returns:



13
14
15
16
17
# 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