Sha256: 3c2084b2c5598c7d6786d53dc4d52a011b0415f1510c410302269ccce89bacea

Contents?: true

Size: 483 Bytes

Versions: 4

Compression:

Stored size: 483 Bytes

Contents

# frozen_string_literal: true

module FreightKit
  class HTTPError < Error
    attr_reader :body, :code

    def initialize(body:, code:)
      @body = body
      @code = code

      super(message)
    end

    def message
      @message ||= ''.tap do |builder|
        builder << "HTTP #{@code}"
        builder << ":\n#{@body}" if @body.present?
      end
    end

    def to_hash
      @to_hash ||= { code: @http.code, headers: @http.headers, body: @http.body }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
freight_kit-0.1.11 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.10 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.7 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.4 lib/freight_kit/errors/http_error.rb