class Kemal::Controller::Halt

Overview

Raised by halt to abort the current request.

The generated route handler rescues it, applies #status_code to the response and returns #response as the body. WebSocket routes close the socket with HTTP::WebSocket::CloseCode::PolicyViolation instead, using #response as the reason.

Raise it directly when halt isn't in scope, e.g. from a helper defined in an included module rather than in the controller itself:

raise Kemal::Controller::Halt.new(403, "Forbidden")

Defined in:

kemal/controller.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(status : HTTP::Status | Int32 = 200, response : String = "") #

[View source]

Instance Method Detail

def response : String #

The response body, or the WebSocket close reason.


[View source]
def status_code : Int32 #

The HTTP status code to respond with.


[View source]