Sha256: 331967ce0dda209706d0fa8736d94e5bc7bd0e9e3990fe43bc9c336ebccc8902

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

module Bright
  class ResponseError < StandardError
    attr_reader :response
    attr_reader :uri

    def initialize(response, uri = nil)
      @response = response
      @uri = uri
    end

    def to_s
      "Failed with #{response.code} #{response.message if response.respond_to?(:message)}".strip
    end

    def body
      response.body
    end

    def server_error?
      (500..599).include?(response&.code.to_i)
    end
  end

  class UnknownAttributeError < NoMethodError
    attr_reader :record, :attribute

    def initialize(record, attribute)
      @record = record
      @attribute = attribute
      super("unknown attribute '#{attribute}' for #{@record.class}.")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bright-2.1 lib/bright/errors.rb
bright-2.0 lib/bright/errors.rb