Class: AtlasRb::Middleware::RaiseOnReadOnlyMode
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- AtlasRb::Middleware::RaiseOnReadOnlyMode
- Defined in:
- lib/atlas_rb/middleware/raise_on_read_only_mode.rb
Overview
Translates Atlas's maintenance-window refusal into a typed Ruby exception.
Atlas refuses every write-shaped action while the repository-wide
read-only window is open, answering 503 Service Unavailable with the
discriminator error: "read_only_mode" and a Retry-After header. This
middleware keys on the status + discriminator pair and raises
ReadOnlyModeError.
Why path-independent
Modelled on RaiseOnStaleResource, not RaiseOnResourceError. A maintenance window refuses writes on every path, so a path-keyed rule would have to enumerate the whole write surface and would go stale the moment Atlas grows an endpoint.
Why the discriminator matters
A 503 from a reverse proxy while Atlas restarts carries no JSON body. That is a different condition with a different remedy, and it keeps passing through untouched — only Atlas's own envelope raises.
Instance Method Summary collapse
Instance Method Details
#on_complete(env) ⇒ void
This method returns an undefined value.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/atlas_rb/middleware/raise_on_read_only_mode.rb', line 30 def on_complete(env) return unless env.status == 503 body = parse_json(env.body) return unless body.is_a?(Hash) && body["error"] == "read_only_mode" raise AtlasRb::ReadOnlyModeError.new( body["message"], code: body["error"], retry_after: env.response_headers&.[]("retry-after")&.to_i ) end |