Class: HTTPX::ErrorResponse

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/httpx/response.rb

Constant Summary

Constants included from Loggable

Loggable::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log, #log_exception

Constructor Details

#initialize(request, error, options) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.



243
244
245
246
247
248
# File 'lib/httpx/response.rb', line 243

def initialize(request, error, options)
  @request = request
  @error = error
  @options = Options.new(options)
  log_exception(@error)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, &block) ⇒ Object

rubocop:disable Style/MissingRespondToMissing

Raises:

  • (NoMethodError)


259
260
261
262
263
# File 'lib/httpx/response.rb', line 259

def method_missing(meth, *, &block)
  raise NoMethodError, "undefined response method `#{meth}' for error response" if Response.public_method_defined?(meth)

  super
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



241
242
243
# File 'lib/httpx/response.rb', line 241

def error
  @error
end

#requestObject (readonly)

Returns the value of attribute request.



241
242
243
# File 'lib/httpx/response.rb', line 241

def request
  @request
end

Instance Method Details

#raise_for_statusObject

Raises:



254
255
256
# File 'lib/httpx/response.rb', line 254

def raise_for_status
  raise @error
end

#statusObject



250
251
252
# File 'lib/httpx/response.rb', line 250

def status
  @error.message
end