Debugging Status 500 Errors in Production

Deploying a rails project to Heroku can be a headache. In production on Heroku, you are running your application on their servers. Thus you become the client to your app. If you run across a problem with your user experience such as a bad request, you will recieve a splash page saying that an error has happened. The page will have nothing on it, but a http status code and a prompt for you to check heroku logs if you are the admin. Most times, you will probably be able to figure out the problem if you have a 300 or 400 status code. However, things become very difficult if you get a 500 error in production. The 500 status error means that something went wrong with the code in your application. However, the page that you will get back will have no real information to help you fix your error and your heroku logs will be almost as useless as your heroku error splash page.

Thankfully there is a way to debug your applications status 500 errors via your production environment. In rails there is a setting in /configs/environments/production.rb called:

config.consider_all_requests_local = false

This setting is set by default to false. This is a security measure, which is definitely very useful because you dont want your code to be shown if an error is thrown by your application. But if you really need to see whats going on and you need a clue and nothing seems to be working. You can set this value to true and go through the process that you would in order to get the 500 error.

config.consider_all_requests_local = true

This will give you the same error page that you use in development to debug your problem code. Once you see the error causing code, you have to make sure you reset the settings to false. Make sure you do this very fast. Im very sure there has to be a better way to see where the error is than to risk the security of your application in this way. I will figure it out and then I will make a post on that. But this is a pretty good and straight forward alternative.