Exception: PatientHttp::Error

Inherits:
StandardError
  • Object
show all
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

HttpError, RedirectError, RequestError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(hash) ⇒ Error

Load an error from a hash, dispatching to the appropriate subclass.

Parameters:

  • hash (Hash)

    hash representation of the error

Returns:

  • (Error)

    the reconstructed error



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_jsonHash

Serialize to a hash for JSON encoding. Subclasses must implement this.

Returns:

  • (Hash)

    hash representation of the error

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/patient_http/error.rb', line 64

def as_json
  raise NotImplementedError, "Subclasses must implement #as_json"
end

#callback_argsCallbackArgs

Returns the callback arguments.

Returns:

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/patient_http/error.rb', line 57

def callback_args
  raise NotImplementedError, "Subclasses must implement #callback_args"
end

#durationFloat

Returns Request duration in seconds.

Returns:

  • (Float)

    Request duration in seconds

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/patient_http/error.rb', line 42

def duration
  raise NotImplementedError, "Subclasses must implement #duration"
end

#error_classClass

Returns the class of the exception that caused the error.

Returns:

  • (Class)

    the class of the exception that caused the error

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/patient_http/error.rb', line 52

def error_class
  raise NotImplementedError, "Subclasses must implement #error_class"
end

#error_typeSymbol

Returns the error type symbol. Provided for compatibility with RequestError.

Returns:

  • (Symbol)

    the error type



27
28
29
# File 'lib/patient_http/error.rb', line 27

def error_type
  :unknown
end

#http_methodSymbol

Returns HTTP method.

Returns:

  • (Symbol)

    HTTP method

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/patient_http/error.rb', line 37

def http_method
  raise NotImplementedError, "Subclasses must implement #http_method"
end

#request_idString

Returns Unique request identifier.

Returns:

  • (String)

    Unique request identifier

Raises:

  • (NotImplementedError)


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.

Parameters:

  • options (Hash) (defaults to: nil)

    options to pass to JSON.generate (for ActiveSupport compatibility)

Returns:

  • (String)

    JSON representation



72
73
74
# File 'lib/patient_http/error.rb', line 72

def to_json(options = nil)
  JSON.generate(as_json, options)
end

#urlString

Returns Request URL.

Returns:

  • (String)

    Request URL

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/patient_http/error.rb', line 32

def url
  raise NotImplementedError, "Subclasses must implement #url"
end