Exception: Rerout::Error

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

Instance Method Summary collapse

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(message)
  @code = code
  @status = status
  @path = path
  @timestamp = timestamp
  @details = details
end

Instance Attribute Details

#codeString (readonly)

Returns stable error code, either from the API or synthetic.

Returns:

  • (String)

    stable error code, either from the API or synthetic.



17
18
19
# File 'lib/rerout/error.rb', line 17

def code
  @code
end

#detailsObject? (readonly)

Returns raw parsed payload or original cause.

Returns:

  • (Object, nil)

    raw parsed payload or original cause.



29
30
31
# File 'lib/rerout/error.rb', line 29

def details
  @details
end

#pathString? (readonly)

Returns API path that returned the error, when available.

Returns:

  • (String, nil)

    API path that returned the error, when available.



23
24
25
# File 'lib/rerout/error.rb', line 23

def path
  @path
end

#statusInteger (readonly)

Returns HTTP status, or 0 when the request never reached the server.

Returns:

  • (Integer)

    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

#timestampString? (readonly)

Returns ISO-8601 server timestamp, when supplied.

Returns:

  • (String, nil)

    ISO-8601 server timestamp, when supplied.



26
27
28
# File 'lib/rerout/error.rb', line 26

def timestamp
  @timestamp
end

Instance Method Details

#inspectObject

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=#{message.inspect} path=#{path.inspect} " \
    "timestamp=#{timestamp.inspect}>"
end

#rate_limited?Boolean

Returns true when the failure is HTTP 429.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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