Sha256: 1f40871219846b0a22afd24ea67da715f48d2f02a970648dfeb4ecce9ff344c0

Contents?: true

Size: 790 Bytes

Versions: 13

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

module Cased
  class Response
    attr_reader :body
    attr_reader :exception

    def initialize(response: nil, exception: nil)
      @response = response
      @body = response&.body
      @exception = exception
    end

    def error
      @exception.presence || (body && body['error']).presence
    end

    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

    def success?
      return false if @response.nil?

      @response.success?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cased-ruby-0.5.2 lib/cased/response.rb
cased-ruby-0.5.1 lib/cased/response.rb
cased-ruby-0.5.0 lib/cased/response.rb
cased-ruby-0.4.8 lib/cased/response.rb
cased-ruby-0.4.7 lib/cased/response.rb
cased-ruby-0.4.6 lib/cased/response.rb
cased-ruby-0.4.5 lib/cased/response.rb
cased-ruby-0.4.4 lib/cased/response.rb
cased-ruby-0.4.3 lib/cased/response.rb
cased-ruby-0.4.2 lib/cased/response.rb
cased-ruby-0.4.1 lib/cased/response.rb
cased-ruby-0.4.0 lib/cased/response.rb
cased-ruby-0.3.3 lib/cased/response.rb