Class: Kailash::Nexus::NexusHandlerError
- Inherits:
-
Error
- Object
- Error
- Kailash::Nexus::NexusHandlerError
- Defined in:
- lib/kailash.rb
Overview
Typed exception a handler_extract callable raises to emit a
non-default HTTP response with a structured body (#404 S5b).
The Rust-side extractor dispatch rescues this exception and maps
its status + body to the outgoing HTTP response. Any other
exception falls through to the legacy 400 "Ruby handler raised"
path for backward compatibility with S5a.
The superclass is STATED, not inherited by accident of load order.
The native extension defines this class first, as
Kailash::Nexus::NexusHandlerError < Kailash::Error
(ext/kailash/src/nexus.rs, define_error), and the require at the top
of this file runs before this block -- so a bare class NexusHandlerError
REOPENS that exception class and everything works. It works because of the
ordering, and nothing said so.
If that ordering ever changed, a bare reopen would silently create a NEW
class inheriting Object, and the feature would stop working at two
separate points. Measured on Ruby 3.3.11 against the same class body
evaluated without the extension loaded:
superclass: Object
k.new("boom", status: 422)
-> ArgumentError: wrong number of arguments (given 1, expected 0)
(`super(message)` reaching `Object#initialize`)
raise k.new -> TypeError: exception class/object expected
And the rescue NexusHandlerError below would not raise -- it would
simply never match, which is the quieter of the two failures. Between
them the documented status/body mapping would have no reachable entry
point, with this comment still describing it.
Naming the superclass turns that into a loud failure at load: a
NameError if the extension has not defined Kailash::Error yet, or a
TypeError: superclass mismatch if it ever defines this class differently.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(message = nil, status: 500, body: nil) ⇒ NexusHandlerError
constructor
A new instance of NexusHandlerError.
Constructor Details
#initialize(message = nil, status: 500, body: nil) ⇒ NexusHandlerError
Returns a new instance of NexusHandlerError.
81 82 83 84 85 |
# File 'lib/kailash.rb', line 81 def initialize( = nil, status: 500, body: nil) super( || "Kailash::Nexus::NexusHandlerError(status=#{status})") @status = Integer(status) @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
79 80 81 |
# File 'lib/kailash.rb', line 79 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
79 80 81 |
# File 'lib/kailash.rb', line 79 def status @status end |