Exception: Fluence::Gateway::RequestError
- Defined in:
- lib/fluence/gateway/errors.rb
Overview
Raised when the target service responded with a 4xx/5xx HTTP status.
Wraps the underlying OAuth2::Error but hides the OAuth2 dependency
from callers and exposes status, body, and headers directly so
consumers don't need to reach into error.response.*.
Two statuses get a subclass of their own, because they call for a
different reaction than a plain 4xx/5xx: RateLimitedError (429) and
UpstreamUnavailableError (502, 503, 504). Rescuing RequestError
still catches both.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ String?
readonly
Returns the raw response body of the failed response.
-
#headers ⇒ Hash?
readonly
Returns the response headers of the failed response.
-
#status ⇒ Integer?
readonly
Returns the HTTP status code of the failed response.
Class Method Summary collapse
-
.build(message, response:) ⇒ RequestError
Picks the error class matching the response status and instantiates it: RateLimitedError for 429, UpstreamUnavailableError for 502, 503 and 504,
RequestErrorotherwise.
Instance Method Summary collapse
-
#initialize(message, response: nil) ⇒ RequestError
constructor
Builds a new RequestError wrapping the given message and optional response.
Constructor Details
#initialize(message, response: nil) ⇒ RequestError
Builds a new RequestError wrapping the given message and optional response. Callers typically do not call this directly — the gateway client raises it automatically when the target service returns 4xx/5xx.
Instance Attribute Details
#body ⇒ String? (readonly)
Returns the raw response body of the failed response.
#headers ⇒ Hash? (readonly)
Returns the response headers of the failed response.
#status ⇒ Integer? (readonly)
Returns the HTTP status code of the failed response.
Class Method Details
.build(message, response:) ⇒ RequestError
Picks the error class matching the response status and instantiates
it: Fluence::Gateway::RateLimitedError for 429, UpstreamUnavailableError for 502,
503 and 504, RequestError otherwise. A blank message is replaced by
"HTTP <status>", so an empty error body (what a gateway sends when
it could not reach the backend) still says which status came back.