class Oauth2ApiClient::ResponseError
The ResponseError
class is the main exception class of Oauth2ApiClient
and is raised when a request fails with some status code other than 2xx. Using the exception object, you still have access to the response. Moreover, there are exception classes for all 4xx and 5xx errors.
@example
begin client.post("/orders", json: { address: "..." }) rescue Oauth2ApiClient::ResponseError::NotFound => e e.response # => HTTP::Response rescue Oauth2ApiClient::ResponseError::BadRequest => e # ... rescue Oauth2ApiClient::ResponseError => e # ... end
Constants
- STATUSES
Attributes
response[R]
Public Class Methods
const_name(message)
click to toggle source
@api private
Returns a sanitized version to be used as a constant name for a given http error message.
# File lib/oauth2_api_client/response_error.rb, line 90 def self.const_name(message) message.gsub(/[^a-zA-Z0-9]/, "") end
for(response)
click to toggle source
@api private
Returns the exception class for a status code of the given response.
# File lib/oauth2_api_client/response_error.rb, line 79 def self.for(response) return const_get(const_name(STATUSES[response.code])).new(response) if STATUSES.key?(response.code) new(response) end
new(response)
click to toggle source
# File lib/oauth2_api_client/response_error.rb, line 67 def initialize(response) @response = response end
Public Instance Methods
to_s()
click to toggle source
# File lib/oauth2_api_client/response_error.rb, line 71 def to_s "#{self.class.name} (#{response.code}, #{response.uri}): #{response.body}" end