Exception: PatientHttp::Error
- Inherits:
-
StandardError
- Object
- StandardError
- PatientHttp::Error
- Defined in:
- lib/patient_http/error.rb
Overview
Base error class for async HTTP errors. This is an abstract class that defines the common error interface.
Direct Known Subclasses
Class Method Summary collapse
-
.load(hash) ⇒ Error
Load an error from a hash, dispatching to the appropriate subclass.
Instance Method Summary collapse
-
#as_json ⇒ Hash
Serialize to a hash for JSON encoding.
-
#callback_args ⇒ CallbackArgs
The callback arguments.
-
#duration ⇒ Float
Request duration in seconds.
-
#error_class ⇒ Class
The class of the exception that caused the error.
-
#error_type ⇒ Symbol
Returns the error type symbol.
-
#http_method ⇒ Symbol
HTTP method.
-
#request_id ⇒ String
Unique request identifier.
-
#to_json(options = nil) ⇒ String
Serialize to JSON string.
-
#url ⇒ String
Request URL.
Class Method Details
.load(hash) ⇒ Error
Load an error from a hash, dispatching to the appropriate subclass.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/patient_http/error.rb', line 12 def load(hash) # Dispatch based on hash structure if hash.key?("response") HttpError.load(hash) elsif hash.key?("redirects") RedirectError.load(hash) else RequestError.load(hash) end end |
Instance Method Details
#as_json ⇒ Hash
Serialize to a hash for JSON encoding. Subclasses must implement this.
64 65 66 |
# File 'lib/patient_http/error.rb', line 64 def as_json raise NotImplementedError, "Subclasses must implement #as_json" end |
#callback_args ⇒ CallbackArgs
Returns the callback arguments.
57 58 59 |
# File 'lib/patient_http/error.rb', line 57 def callback_args raise NotImplementedError, "Subclasses must implement #callback_args" end |
#duration ⇒ Float
Returns Request duration in seconds.
42 43 44 |
# File 'lib/patient_http/error.rb', line 42 def duration raise NotImplementedError, "Subclasses must implement #duration" end |
#error_class ⇒ Class
Returns the class of the exception that caused the error.
52 53 54 |
# File 'lib/patient_http/error.rb', line 52 def error_class raise NotImplementedError, "Subclasses must implement #error_class" end |
#error_type ⇒ Symbol
Returns the error type symbol. Provided for compatibility with RequestError.
27 28 29 |
# File 'lib/patient_http/error.rb', line 27 def error_type :unknown end |
#http_method ⇒ Symbol
Returns HTTP method.
37 38 39 |
# File 'lib/patient_http/error.rb', line 37 def http_method raise NotImplementedError, "Subclasses must implement #http_method" end |
#request_id ⇒ String
Returns Unique request identifier.
47 48 49 |
# File 'lib/patient_http/error.rb', line 47 def request_id raise NotImplementedError, "Subclasses must implement #request_id" end |
#to_json(options = nil) ⇒ String
Serialize to JSON string.
72 73 74 |
# File 'lib/patient_http/error.rb', line 72 def to_json( = nil) JSON.generate(as_json, ) end |
#url ⇒ String
Returns Request URL.
32 33 34 |
# File 'lib/patient_http/error.rb', line 32 def url raise NotImplementedError, "Subclasses must implement #url" end |