class Cased::Response

Attributes

body[R]
exception[R]

Public Class Methods

new(response: nil, exception: nil) click to toggle source
# File lib/cased/response.rb, line 8
def initialize(response: nil, exception: nil)
  @response = response
  @body = response&.body
  @exception = exception
end

Public Instance Methods

error() click to toggle source
# File lib/cased/response.rb, line 14
def error
  @exception.presence || (body && body['error']).presence
end
error?() click to toggle source
# File lib/cased/response.rb, line 18
def error?
  # If there was an exception during the execution of the request.
  return true if @exception.present?

  # If the HTTP response was outside of 200-299
  return true unless @response.success?

  # If the HTTP response contained an error key.
  return true if body && body['error'].present?

  false
end
success?() click to toggle source
# File lib/cased/response.rb, line 31
def success?
  return false if @response.nil?

  @response.success?
end