{"title":"Halt!","description":"","section":"guides/controllers","version":"v1.5","path":"guides/controllers/halt","canonical_url":"https://amberframework.org/docs/v1.5/guides/controllers/halt","markdown_url":"https://amberframework.org/docs/v1.5/guides/controllers/halt.md","inherited":true,"content_markdown":"# Halt!\n\nSometimes we don't want a request to continue executing; maybe an error has occurred or perhaps an operation is taking too long and we would like to abort the execution of the request. Amber provides a `halt!` method to controllers.\n\nWhen you want a request to cease and return a particular message rather then rendering a page, you use Amber `halt!` to stop the request from continue execution.\n\n```crystal\nclass UserController < ApplicationController\n  def index\n    halt!(403, \"Forbidden\") if params[:user_id].nil?\n    render \"index.slang\"\n  end\nend\n```\n\nA status code of `403` was returned, and the content in `render` will not be delivered to the client.\n\nThe next time you’re building an Amber application, consider using halt to simplify error handling.\n\n## Halt! and redirect\\_to\n\nUnlike other frameworks Amber `redirect_to` stops the current execution of the request and performs the redirection at that given time.\n\nFor example, in other frameworks you will have to do something similar to:\n\n```crystal\nclass UserController < ApplicationController\n  def index\n    if some_condition\n        if some_condition\n            redirect_to(path_one) and return\n            # Or another approach\n            return redirect_to(path_one)\n        end\n    end\n  end\nend\n```\n\nAs you probably noticed there is an explicit return, this explicit return is something that is not needed with Amber. Since `redirect_to` uses the `halt!` method in the background."}