Exception: Uber::Error

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

Overview

Custom error class for rescuing from all Uber errors

Direct Known Subclasses

ClientError, ServerError

Defined Under Namespace

Modules: Code Classes: BadRequest, ClientError, ConfigurationError, Forbidden, InternalServerError, NotAcceptable, NotFound, RateLimited, RequestTimeout, ServerError, Unauthorized, UnprocessableEntity

Constant Summary collapse

Codes =

rubocop:disable ConstantName

Code

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', rate_limit = {}, code = nil) ⇒ Uber::Error

Initializes a new Error object

Parameters:

  • exception (Exception, String)
  • rate_limit (Hash) (defaults to: {})
  • code (Integer) (defaults to: nil)


73
74
75
76
77
# File 'lib/uber/error.rb', line 73

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#rate_limitObject (readonly)

Returns the value of attribute rate_limit.



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

def rate_limit
  @rate_limit
end

Class Method Details

.errorsHash

Returns:

  • (Hash)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/uber/error.rb', line 32

def errors
  @errors ||= {
    400 => Uber::Error::BadRequest,
    401 => Uber::Error::Unauthorized,
    403 => Uber::Error::Forbidden,
    404 => Uber::Error::NotFound,
    406 => Uber::Error::NotAcceptable,
    422 => Uber::Error::UnprocessableEntity,
    429 => Uber::Error::RateLimited,
    500 => Uber::Error::InternalServerError
  }
end

.from_response(response) ⇒ Uber::Error

Create a new error from an HTTP response

Parameters:

  • response (Faraday::Response)

Returns:



26
27
28
29
# File 'lib/uber/error.rb', line 26

def from_response(response)
  message, code = parse_error(response.body)
  new(message, response.response_headers, code)
end