Exception: Rerout::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Rerout::Error
- Defined in:
- lib/rerout/error.rb
Overview
Raised for any Rerout API failure — bad request, auth issue, rate limit, network failure, timeout, or unparseable response.
The #code field carries the stable string identifier returned by the Rerout API (e.g. ‘bad_target_url`, `rate_limited`, `not_found`) so callers can branch on it without parsing the human-readable #message.
For network/timeout/parse failures the #code is one of the synthetic values: ‘network_error`, `timeout`, `unexpected_response`, `unauthorized`, `forbidden`, `not_found`, `rate_limited`, `server_error`, `client_error`, `missing_api_key`.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
Stable error code, either from the API or synthetic.
-
#details ⇒ Object?
readonly
Raw parsed payload or original cause.
-
#path ⇒ String?
readonly
API path that returned the error, when available.
-
#status ⇒ Integer
readonly
HTTP status, or 0 when the request never reached the server.
-
#timestamp ⇒ String?
readonly
ISO-8601 server timestamp, when supplied.
Instance Method Summary collapse
-
#initialize(message:, code:, status: 0, path: nil, timestamp: nil, details: nil) ⇒ Error
constructor
A new instance of Error.
-
#inspect ⇒ Object
A developer-friendly description.
-
#rate_limited? ⇒ Boolean
True when the failure is HTTP 429.
-
#server_error? ⇒ Boolean
True when the failure is HTTP 5xx.
Constructor Details
#initialize(message:, code:, status: 0, path: nil, timestamp: nil, details: nil) ⇒ Error
Returns a new instance of Error.
31 32 33 34 35 36 37 38 |
# File 'lib/rerout/error.rb', line 31 def initialize(message:, code:, status: 0, path: nil, timestamp: nil, details: nil) super() @code = code @status = status @path = path @timestamp = @details = details end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns stable error code, either from the API or synthetic.
17 18 19 |
# File 'lib/rerout/error.rb', line 17 def code @code end |
#details ⇒ Object? (readonly)
Returns raw parsed payload or original cause.
29 30 31 |
# File 'lib/rerout/error.rb', line 29 def details @details end |
#path ⇒ String? (readonly)
Returns API path that returned the error, when available.
23 24 25 |
# File 'lib/rerout/error.rb', line 23 def path @path end |
#status ⇒ Integer (readonly)
Returns HTTP status, or 0 when the request never reached the server.
20 21 22 |
# File 'lib/rerout/error.rb', line 20 def status @status end |
#timestamp ⇒ String? (readonly)
Returns ISO-8601 server timestamp, when supplied.
26 27 28 |
# File 'lib/rerout/error.rb', line 26 def @timestamp end |
Instance Method Details
#inspect ⇒ Object
A developer-friendly description. Kept separate from #message (the raw human message) so logging the error shows the structured fields without the bare message losing them.
53 54 55 56 57 |
# File 'lib/rerout/error.rb', line 53 def inspect "#<Rerout::Error code=#{code.inspect} status=#{status} " \ "message=#{.inspect} path=#{path.inspect} " \ "timestamp=#{.inspect}>" end |
#rate_limited? ⇒ Boolean
Returns true when the failure is HTTP 429.
41 42 43 |
# File 'lib/rerout/error.rb', line 41 def rate_limited? status == 429 end |
#server_error? ⇒ Boolean
Returns true when the failure is HTTP 5xx.
46 47 48 |
# File 'lib/rerout/error.rb', line 46 def server_error? status >= 500 && status < 600 end |