Exception: PatientHttp::RedirectError

Inherits:
Error
  • Object
show all
Defined in:
lib/patient_http/redirect_error.rb

Overview

Base class for redirect-related errors. These errors occur when redirect handling fails due to too many redirects or a redirect loop.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#to_json

Constructor Details

#initialize(message, url:, http_method:, duration:, request_id:, redirects:, callback_args: nil) ⇒ RedirectError

Initializes a new RedirectError.

Parameters:

  • message (String)

    Error message

  • url (String)

    Request URL

  • http_method (Symbol, String)

    HTTP method

  • duration (Float)

    Request duration in seconds

  • request_id (String)

    Unique request identifier

  • redirects (Array<String>)

    URLs visited during redirect chain

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

    callback arguments (string keys)



50
51
52
53
54
55
56
57
58
# File 'lib/patient_http/redirect_error.rb', line 50

def initialize(message, url:, http_method:, duration:, request_id:, redirects:, callback_args: nil)
  super(message)
  @url = url
  @http_method = http_method&.to_sym
  @duration = duration
  @request_id = request_id
  @redirects = redirects || []
  @callback_args_data = callback_args || {}
end

Instance Attribute Details

#durationFloat (readonly)

Returns Request duration in seconds.

Returns:

  • (Float)

    Request duration in seconds



15
16
17
# File 'lib/patient_http/redirect_error.rb', line 15

def duration
  @duration
end

#http_methodSymbol (readonly)

Returns HTTP method.

Returns:

  • (Symbol)

    HTTP method



12
13
14
# File 'lib/patient_http/redirect_error.rb', line 12

def http_method
  @http_method
end

#redirectsArray<String> (readonly)

Returns URLs that were visited during redirect chain.

Returns:

  • (Array<String>)

    URLs that were visited during redirect chain



21
22
23
# File 'lib/patient_http/redirect_error.rb', line 21

def redirects
  @redirects
end

#request_idString (readonly)

Returns Unique request identifier.

Returns:

  • (String)

    Unique request identifier



18
19
20
# File 'lib/patient_http/redirect_error.rb', line 18

def request_id
  @request_id
end

#urlString (readonly)

Returns Request URL.

Returns:

  • (String)

    Request URL



9
10
11
# File 'lib/patient_http/redirect_error.rb', line 9

def url
  @url
end

Class Method Details

.load(hash) ⇒ RedirectError

Reconstruct a RedirectError from a hash

Parameters:

  • hash (Hash)

    hash representation

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/patient_http/redirect_error.rb', line 28

def load(hash)
  error_class = ClassHelper.resolve_class_name(hash["error_class"])
  error_class.new(
    url: hash["url"],
    http_method: hash["http_method"]&.to_sym,
    duration: hash["duration"],
    request_id: hash["request_id"],
    redirects: hash["redirects"] || [],
    callback_args: hash["callback_args"]
  )
end

Instance Method Details

#as_jsonHash

Convert to hash with string keys for serialization

Returns:

  • (Hash)

    hash representation



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/patient_http/redirect_error.rb', line 82

def as_json
  {
    "error_class" => self.class.name,
    "url" => url,
    "http_method" => http_method.to_s,
    "duration" => duration,
    "request_id" => request_id,
    "redirects" => redirects,
    "callback_args" => @callback_args_data
  }
end

#callback_argsCallbackArgs

Returns the callback arguments as a CallbackArgs object.

Returns:



75
76
77
# File 'lib/patient_http/redirect_error.rb', line 75

def callback_args
  @callback_args ||= CallbackArgs.load(@callback_args_data)
end

#error_classClass

Returns the class of the exception. This is for compatibility with RequestError.

Returns:

  • (Class)

    the class of the exception. This is for compatibility with RequestError.



68
69
70
# File 'lib/patient_http/redirect_error.rb', line 68

def error_class
  self.class
end

#error_typeSymbol

Returns the error type symbol.

Returns:

  • (Symbol)

    the error type



63
64
65
# File 'lib/patient_http/redirect_error.rb', line 63

def error_type
  :redirect
end