class Uber::Error
Custom error class for rescuing from all Uber
errors
Constants
- Codes
Attributes
code[R]
rate_limit[R]
Public Class Methods
errors()
click to toggle source
@return [Hash]
# 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)
click to toggle source
Create a new error from an HTTP response
@param response [Faraday::Response] @return [Uber::Error]
# File lib/uber/error.rb, line 26 def from_response(response) message, code = parse_error(response.body) new(message, response.response_headers, code) end
new(message = '', rate_limit = {}, code = nil)
click to toggle source
Initializes a new Error
object
@param exception [Exception, String] @param rate_limit
[Hash] @param code [Integer] @return [Uber::Error]
Calls superclass method
# 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
Private Class Methods
extract_message_from_errors(body)
click to toggle source
# File lib/uber/error.rb, line 57 def extract_message_from_errors(body) first = Array(body[:errors]).first if first.is_a?(Hash) [first[:message].chomp, first[:code]] else [first.chomp, nil] end end
parse_error(body)
click to toggle source
# File lib/uber/error.rb, line 47 def parse_error(body) if body.nil? ['', nil] elsif body[:error] [body[:error], nil] elsif body[:errors] extract_message_from_errors(body) end end