Exception: TocDoc::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/toc_doc/core/error.rb

Overview

Raised when an HTTP response is received but indicates an error.

Carries the raw response details so callers can act on them without needing to reach into Faraday internals.

Examples:

rescue TocDoc::ResponseError => e
  puts e.status   # => 404
  puts e.body     # => '{"error":"not found"}'
  puts e.headers  # => {"content-type"=>"application/json"}

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body: nil, headers: nil, message: nil) ⇒ ResponseError

Returns a new instance of ResponseError.

Parameters:

  • status (Integer)

    the HTTP status code

  • body (String, nil) (defaults to: nil)

    the raw response body

  • headers (Hash, nil) (defaults to: nil)

    the response headers

  • message (String, nil) (defaults to: nil)

    optional override for the error message; defaults to +"HTTP ##status"+



53
54
55
56
57
58
# File 'lib/toc_doc/core/error.rb', line 53

def initialize(status:, body: nil, headers: nil, message: nil)
  @status = status
  @body = body
  @headers = headers
  super(message || "HTTP #{status}")
end

Instance Attribute Details

#bodyString? (readonly)

Returns the raw response body.

Returns:

  • (String, nil)

    the raw response body



43
44
45
# File 'lib/toc_doc/core/error.rb', line 43

def body
  @body
end

#headersHash? (readonly)

Returns the response headers.

Returns:

  • (Hash, nil)

    the response headers



46
47
48
# File 'lib/toc_doc/core/error.rb', line 46

def headers
  @headers
end

#statusInteger (readonly)

Returns the HTTP status code.

Returns:

  • (Integer)

    the HTTP status code



40
41
42
# File 'lib/toc_doc/core/error.rb', line 40

def status
  @status
end