Exception: X::TooManyRedirects

Inherits:
Error
  • Object
show all
Includes:
RequestContext
Defined in:
x-core/lib/x/core/errors/too_many_redirects.rb

Overview

Raised for a response that redirected more times than the client's max_redirects allows

The message names the request whose redirect was one too many, and #http_method and #uri read it: the request that redirect answered, which is the one a client sent last, rather than the one it was first asked for.

Examples:

Tell an endpoint that redirects in a loop from the others

rescue X::TooManyRedirects => e
  logger.warn("#{e.uri} keeps redirecting")

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, http_method: nil, uri: nil) ⇒ TooManyRedirects

Initialize a new TooManyRedirects

Public, so that code that rescues a TooManyRedirects can be tested with one built by hand, as RedirectHandler builds one, or raised with no message, as any exception is. The error names the request, when given its method and URI, as x-core names the request whose redirect was one too many.

Examples:

Create an error

error = X::TooManyRedirects.new("Too many redirects", http_method: :get, uri: URI("https://api.x.com/2/users/me"))

Parameters:

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

    what went wrong, or nil for the name of the class, as an exception raised with no message is named, which names no request

  • http_method (Symbol, String, nil) (defaults to: nil) —

    the method of the request whose redirect was one too many, in any case

  • uri (URI::Generic, nil) (defaults to: nil) —

    the URI of the request whose redirect was one too many



47
48
49
50
# File 'x-core/lib/x/core/errors/too_many_redirects.rb', line 47

def initialize(message = nil, http_method: nil, uri: nil)
  name_request(http_method, uri)
  super(message && message_naming_request(message))
end

Instance Method Details

#http_method ⇒ Symbol?

The HTTP method the request whose redirect was one too many was sent with

Examples:

Tell a read that redirected in a loop from a write

writes_failed += 1 unless error.http_method.eql?(:get)

Returns:

  • (Symbol, nil) —

    the method, as :get, :post, :put, or :delete, or nil for an error built without one



# File 'x-core/lib/x/core/errors/too_many_redirects.rb', line 20

#uri ⇒ URI::Generic?

The URI the request whose redirect was one too many was sent to

Examples:

Get the path that keeps redirecting

error.uri.path # => "/2/users/me"

Returns:

  • (URI::Generic, nil) —

    the URI, or nil for an error built without one



# File 'x-core/lib/x/core/errors/too_many_redirects.rb', line 20