Exception: AtlasRb::ReadOnlyModeError

Inherits:
Error
  • Object
show all
Defined in:
lib/atlas_rb/errors.rb

Overview

Raised when Atlas refuses a write because the repository-wide maintenance window is open: an HTTP 503 whose body carries error: "read_only_mode".

Deliberately NOT ForbiddenError. Atlas could have refused with a 403, but a 403 is a statement about the caller's rights, and Cerberus renders ForbiddenError as a permission-denied page. During a migration window that is a lie — the librarian's rights are fine, the repository is closed.

Without this the failure mode is worse than an error: a 503 reaches neither Middleware::RaiseOnStaleResource (409-only) nor Middleware::RaiseOnResourceError (403/422-only), and the response body carries no "work" / "collection" key, so the binding unwraps nil and returns it. The write silently no-ops and the UI reports success — a librarian saves metadata, sees no error, and loses the edit.

rescue AtlasRb::ReadOnlyModeError => e
flash.now[:alert] = e.message
response.headers["Retry-After"] = e.retry_after.to_s if e.retry_after

Read GET /maintenance (Maintenance.read) to render a banner before a caller trips this; that endpoint stays answerable while the window is open, precisely so a client can see the flag it is honouring.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code: nil, retry_after: nil) ⇒ ReadOnlyModeError

Returns a new instance of ReadOnlyModeError.

Parameters:

  • message (String, nil) (defaults to: nil)

    human-readable refusal description.

  • code (String, nil) (defaults to: nil)

    the envelope's error discriminator.

  • retry_after (Integer, nil) (defaults to: nil)

    seconds from the Retry-After header.



416
417
418
419
420
# File 'lib/atlas_rb/errors.rb', line 416

def initialize(message=nil, code: nil, retry_after: nil)
  @code = code
  @retry_after = retry_after
  super(message || "Atlas is in maintenance mode; writes are refused")
end

Instance Attribute Details

#codeString? (readonly)

Returns the envelope's error discriminator ("read_only_mode").

Returns:

  • (String, nil)

    the envelope's error discriminator ("read_only_mode").



407
408
409
# File 'lib/atlas_rb/errors.rb', line 407

def code
  @code
end

#retry_afterInteger? (readonly)

Returns seconds to wait before retrying, from Atlas's Retry-After response header.

Returns:

  • (Integer, nil)

    seconds to wait before retrying, from Atlas's Retry-After response header.



411
412
413
# File 'lib/atlas_rb/errors.rb', line 411

def retry_after
  @retry_after
end