Exception: Ruact::ActionError

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

Overview

Story 8.3 — raised inside a standalone server-action block to surface a non-2xx response without calling ‘render` (which the StandaloneContext does not expose). The endpoint dispatcher rescues this exception class and renders `status` + `body` verbatim, mirroring how a controller-hosted action would call `render(json: …, status: …)`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body: nil, message: nil) ⇒ ActionError

Returns a new instance of ActionError.

Parameters:

  • status (Symbol, Integer)

    HTTP status (e.g. :unprocessable_entity, 422).

  • body (Object) (defaults to: nil)

    the response payload. Hash/Array/scalar values are rendered as JSON; nil renders an empty body.

  • message (String) (defaults to: nil)

    optional message; defaults to “ruact action error (status=<status>)” so the exception is still legible in logs.



59
60
61
62
63
# File 'lib/ruact/errors.rb', line 59

def initialize(status:, body: nil, message: nil)
  @status = status
  @body = body
  super(message || "ruact action error (status=#{status.inspect})")
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



52
53
54
# File 'lib/ruact/errors.rb', line 52

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



52
53
54
# File 'lib/ruact/errors.rb', line 52

def status
  @status
end