How to use Plug halt, or other

  1. What does halt do? I see it in the Phoenix boilerplate. When I try to use it it doesn’t work as expected.
conn
  |> halt()
  IO.inspect("This will run")

What’s the diff btw halting the “Plug pipeline” and just breaking the function?

I’m always missing a return or break function and thought maybe this could be used in place.

  1. Is there a way to break in this way, even if it’s bad practice?

RE:

If you need help with homework or some other theoretical problem please use the Homework Help/Theory section.

This is a theory question I wanted to put in the proper place but could not find that. Sorry :frowning:

Normally, a plug returns a Plug.Conn structure that’s passed along to the next plug in the pipeline.

The halt functions sets a flag in the Plug.Conn structure that tells Plug “stop evaluating the pipeline now”. It doesn’t change the control flow of the function.

3 Likes