Skip to content

Loading…

Need a way to halt connections. #51

Closed
jeregrine opened this Issue · 10 comments

3 participants

@jeregrine
phoenixframework member

RIght now I'm not sure we have a way to halt connections, we can send a response but that doesn't stop phoenix from running the rest of the commands or plugs.

@jeregrine
phoenixframework member
@chrismccord
phoenixframework member

We just started a discussion around this yesterday:
#50

We have a couple options:
1) Provide a few functions internally that set plug state and raise, allowing wrapper plugs to rescue. @josevalim has suggested this route. ie hatlt!(conn)

2) Use tagged tuples and return status via the tuple, ie {:halt, conn, reason}.

The 1st option could be implemented today since it's just raise/rescue. The tagged tuple approach would require our own plug layer and wouldn't play nicely with "regular" plugs. I'm going to flesh out an exceptional approach and see how it feels. The nice thing here is phoenix could provide its own wrapper to rescue from uncaught exceptions and do error reporting/500 page, etc.

@josevalim
phoenixframework member

1) Should be implemented using throw/catch. It is semantically different than raise/rescue.

2) It violates the plug API (so the functions would no longer be plugs).

@chrismccord
phoenixframework member

@josevalim 1) noted - my rubies get me confused sometimes. 2) Agreed. Sounds like 1 is the way we're going.

@jeregrine
phoenixframework member
@josevalim
phoenixframework member

error ... do end is tricky because it cannot handle errors coming from outer plugs. Unless it will be specified in the router (but is the router the place to put such logic?).

@jeregrine
phoenixframework member

I think handling errors in plugs should either be handled within the plug and if its truly exceptional it should be sent up the stack. :)

I imagine the error handler to be specific errors to MY code not code coming from the other gems.

A common pattern in sinatra is

error 404 do
   haml :my_404_page
end 
@jeregrine
phoenixframework member

Sorry s/gems/plug :)

@josevalim
phoenixframework member

@jeregrine keep in mind sinatra's 404 is part of the error handling. what translates an exception into 404? which parts of your stack should end up calling 404 in your app?

@chrismccord
phoenixframework member

Halting is available in master. We can discuss possible error handling (outside of wrapping the call yourself), in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.