Exception: PatientHttp::RedirectError
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#duration ⇒ Float
readonly
Request duration in seconds.
-
#http_method ⇒ Symbol
readonly
HTTP method.
-
#redirects ⇒ Array<String>
readonly
URLs that were visited during redirect chain.
-
#request_id ⇒ String
readonly
Unique request identifier.
-
#url ⇒ String
readonly
Request URL.
Class Method Summary collapse
-
.load(hash) ⇒ RedirectError
Reconstruct a RedirectError from a hash.
Instance Method Summary collapse
-
#as_json ⇒ Hash
Convert to hash with string keys for serialization.
-
#callback_args ⇒ CallbackArgs
Returns the callback arguments as a CallbackArgs object.
-
#error_class ⇒ Class
The class of the exception.
-
#error_type ⇒ Symbol
Returns the error type symbol.
-
#initialize(message, url:, http_method:, duration:, request_id:, redirects:, callback_args: nil) ⇒ RedirectError
constructor
Initializes a new RedirectError.
Methods inherited from Error
Constructor Details
#initialize(message, url:, http_method:, duration:, request_id:, redirects:, callback_args: nil) ⇒ RedirectError
Initializes a new RedirectError.
50 51 52 53 54 55 56 57 58 |
# File 'lib/patient_http/redirect_error.rb', line 50 def initialize(, url:, http_method:, duration:, request_id:, redirects:, callback_args: nil) super() @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
#duration ⇒ Float (readonly)
Returns Request duration in seconds.
15 16 17 |
# File 'lib/patient_http/redirect_error.rb', line 15 def duration @duration end |
#http_method ⇒ Symbol (readonly)
Returns HTTP method.
12 13 14 |
# File 'lib/patient_http/redirect_error.rb', line 12 def http_method @http_method end |
#redirects ⇒ Array<String> (readonly)
Returns URLs that were visited during redirect chain.
21 22 23 |
# File 'lib/patient_http/redirect_error.rb', line 21 def redirects @redirects end |
#request_id ⇒ String (readonly)
Returns Unique request identifier.
18 19 20 |
# File 'lib/patient_http/redirect_error.rb', line 18 def request_id @request_id end |
#url ⇒ String (readonly)
Returns 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
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_json ⇒ Hash
Convert to hash with string keys for serialization
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_args ⇒ CallbackArgs
Returns the callback arguments as a CallbackArgs object.
75 76 77 |
# File 'lib/patient_http/redirect_error.rb', line 75 def callback_args @callback_args ||= CallbackArgs.load(@callback_args_data) end |
#error_class ⇒ Class
Returns 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_type ⇒ Symbol
Returns the error type symbol.
63 64 65 |
# File 'lib/patient_http/redirect_error.rb', line 63 def error_type :redirect end |