Method: Hanami::API::Block::Context#halt

Defined in:
lib/hanami/api/block/context.rb

#halt(status, body = nil) ⇒ Object

Halts the flow of the block and immediately returns with the current HTTP status

Examples:

HTTP Status

get "/authenticate" do
  halt(401)

  # this code will never be reached
end

# It sets a Rack response: [401, {}, ["Unauthorized"]]

HTTP Status and body

get "/authenticate" do
  halt(401, "You shall not pass")

  # this code will never be reached
end

# It sets a Rack response: [401, {}, ["You shall not pass"]]

Since:

  • 0.1.0



55
56
57
58
# File 'lib/hanami/api/block/context.rb', line 55

def halt(status, body = nil)
  body ||= http_status(status)
  throw :halt, [status, body]
end