Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Halt! docs misleading/incorrect #181

Open
matthewmcgarvey opened this issue Jan 16, 2021 · 1 comment
Open

Halt! docs misleading/incorrect #181

matthewmcgarvey opened this issue Jan 16, 2021 · 1 comment

Comments

@matthewmcgarvey
Copy link

For example, the docs show the controller:

 class UserController < ApplicationController
  def index
    halt!(403, "Forbidden") if params[:user_id].nil?
    render "index.slang"
  end
end

and says

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

which is not true. What really happens is that the client receives a response with the status of 403 but the content of the template. The core misunderstanding seems to be from a line further down that says

Unlike other frameworks Amber redirect_to stops the current execution of the request and performs the redirection at that given time...Since redirect_to uses the halt! method in the background.

I think there was a misunderstanding that calling halt! does something to immediately return from whatever it's called in. Maybe it was envisioned to raise an exception? This was never the case, though. The only thing it does is set the content value on the context and the route macro checks that value before running before_filters and the action https://github.com/amberframework/amber/blob/58eea3e147ba384fe4cb7c5f0a63da61b357e356/src/amber/dsl/router.cr#L14-L15

@eliasjpr
Copy link
Contributor

eliasjpr commented May 9, 2021

Would you like to open a PR to improve the docs? @matthewmcgarvey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants