Exception: HTTPX::HTTPError

Inherits:
Error
  • Object
show all
Defined in:
lib/httpx/errors.rb,
sig/errors.rbs

Overview

The exception class for HTTP responses with 4xx or 5xx status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ HTTPError

Creates the instance and assigns the HTTPX::Response response.

Parameters:



106
107
108
109
# File 'lib/httpx/errors.rb', line 106

def initialize(response)
  @response = response
  super("HTTP Error: #{@response.status} #{@response.headers}\n#{@response.body}")
end

Instance Attribute Details

#responseResponse (readonly)

The HTTPX::Response response object this exception refers to.

Returns:



103
104
105
# File 'lib/httpx/errors.rb', line 103

def response
  @response
end

Instance Method Details

#statusInteger

The HTTP response status.

error.status #=> 404

Returns:

  • (Integer)


114
115
116
# File 'lib/httpx/errors.rb', line 114

def status
  @response.status
end