Class: FreightKit::HTTPError

Inherits:
Error
  • Object
show all
Defined in:
lib/freight_kit/errors/http_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, code:) ⇒ HTTPError

Returns a new instance of HTTPError.



7
8
9
10
11
12
# File 'lib/freight_kit/errors/http_error.rb', line 7

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

  super(message)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/freight_kit/errors/http_error.rb', line 5

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/freight_kit/errors/http_error.rb', line 5

def code
  @code
end

Instance Method Details

#messageObject



14
15
16
17
18
19
# File 'lib/freight_kit/errors/http_error.rb', line 14

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

#to_hashObject



21
22
23
# File 'lib/freight_kit/errors/http_error.rb', line 21

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