Sha256: 2672c9ee25ef68a9ac4495dd1295d8dc5dbb0c857dd8d970c3c69f2ae8e610d0

Contents?: true

Size: 495 Bytes

Versions: 4

Compression:

Stored size: 495 Bytes

Contents

# frozen_string_literal: true

module FreightKit
  class HTTPError < FreightKit::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.3 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.2 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.1 lib/freight_kit/errors/http_error.rb
freight_kit-0.1.0 lib/freight_kit/errors/http_error.rb