> For the complete documentation index, see [llms.txt](https://mazeframework.gitbook.io/maze/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mazeframework.gitbook.io/maze/guides/controllers/halt.md).

# Halt!

Sometimes 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. Maze provides a `halt!` method to controllers.

When you want a request to cease and return a particular message rather then rendering a page, you use Maze `halt!` to stop the request from continue execution.

```ruby
class UserController < ApplicationController
  def index
    halt(404, "Forbiden") if params[:user_id].nil?
    reder "index.slang"
  end
end
```

A status code of `404` was returned, and the content in `render` will not be delivered to the client.

The next time you’re building a Maze application, consider using halt to simplify error handling.

## Halt! and redirect\_to

Unlike other frameworks Maze `redirect_to` stops the current execution of the request and performs the redirection at that given time.

For example, in other frameworks you will have to do something similar to:

```ruby
class UserController < ApplicationController
  def index
    if some_condition
        if some_condition
            redirect_to(path_one) and return
            # Or another approach
            return redirect_to(path_one)
        end
    end
  end
end
```

As you probably noticed there is an explicit return, this explicit return is something that is not needed with Maze. Since `redirect_to` uses the `halt!` method in the background.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mazeframework.gitbook.io/maze/guides/controllers/halt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
