0

I am using heroku-buildpack-elixir to deploy an application to Heroku. My application consists of a simple Plug/Cowboy setup. I noticed that when unhandled exceptions occur, a nice error message appears, showing the stack trace and the lines of code where the error appeared.

This is ok for development environments, however on production environments I do not want my code to be visible to visitors. How can I disable or override the default behaviour?

I tried setting the MIX_ENV environment variable to prod in Heroku with no effect.

Raphael Müller
  • 971
  • 2
  • 8
  • 20
  • _Sidenote:_ changing `MIX_ENV` in production does not make much sense since there is even no `mix` application in the first place (unless you have explicitly included it in your release, which is basically wrong in a nutshell.) – Aleksei Matiushkin Sep 06 '18 at 04:41
  • @mudasobwa but it seems that `Mix.env` has the correct value though (look at the accepted answer). Where does it get the value from? – Raphael Müller Sep 06 '18 at 06:23
  • In the correct answer, this code is _compiled_. During the compilation stage `mix` is surely there and `Mix.env` is defined. In production, there is no trail of `mix` anymore. That said, in runtime there is _no conditional_ at all, this piece of code is compiled to void AST. – Aleksei Matiushkin Sep 06 '18 at 06:25
  • @mudasobwa the application is compiled on Heroku, that's why I thought the environment variables would also have effects at the compilation stage. – Raphael Müller Sep 06 '18 at 06:33

1 Answers1

0

wrap the Plug.Debugger statement in an if clause. Running in prod environment no longer show errors as html pages. source

  if Mix.env == :dev do
    use Plug.Debugger, otp_app: :my_app
  end
Constantin Guidon
  • 1,892
  • 16
  • 21
  • 1
    are you using Plug.Debugger ? hard to find the solution without code.... – Constantin Guidon Sep 05 '18 at 16:42
  • Thanks - wrapping `use Plug.Debugger` in an if clause like in the example on https://hexdocs.pm/plug/Plug.Debugger.html does exactly what I need. Could you add this to your answer for future readers? – Raphael Müller Sep 05 '18 at 19:44