0
votes

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.

1
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
@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
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
@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

1 Answers

0
votes

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