title: Handling error in Phoenix/Elixir
body: <p>1) How can I handle "server error" and "page not found" <strong>on the application level</strong>? Where should I put a handler which renders appropriate pages?</p>
  
  <p>That is, if a user goes to "my_website.com/fdafdsafds" -- how can I render the page "error/my_custom_404_page.html" to him?</p>
  
  <p>Or if somewhere in my app an error occurs such as "1 / 0", how can I catch it on the application level?</p>
  
  <p>2) Inside a plug I have this:</p>
  
  <pre><code>  def call(conn, opts) do
      if !some_condition do
        # ....
      else
        # how to render an html template?
        Conn.send_resp(conn, 401, "access denied") |&gt; Conn.halt()
      end
    end
  </code></pre>
  
  <p>How can I render my custom error html template from "error/my_html_template.html" and pass parameters to it?</p>