How to enable error reporting when running rails application in production mode?

I am working in a rails application. I can see the screen below on my production server whenever there is an error. (Text: Sorry, but something went wrong.)

How to enable error reporting on my server to see the actual error? Do I need to make any configuration changes in a Rails application or allow error reporting on my server.

enter image description here

Note. My Ngnix server.

+4
source share
2 answers

If you add this to your config/environments/production.rb :

 config.consider_all_requests_local = true 

You will see the same errors as in development, but also disable caching for the production application, etc.

I would rather have a look at /log/production.log . The same errors are published there, which are usually displayed on the screen.

+12
source

For error reporting, there is a convenient pearl called exception_notification , which sends you mail every time an exception occurs in your application.

If you also want to get detailed and fully customizable error reports on the page, you will need to code a bit. Here is what I use (I would give you a link to where I got this from, but I can no longer find it :()

  • Define ErrorsController as follows:

     class ErrorsController < ApplicationController ERRORS = [ :internal_server_error, :not_found, :unprocessable_entity, :unauthorized ].freeze ERRORS.each do |e| define_method e do respond_to do |format| format.html { render e, :status => e } format.any { head e } end end end 

    end

  • Create an initializer to connect the controller to the Rails exception handling chain:

     require 'action_dispatch/middleware/show_exceptions' module ActionDispatch class ShowExceptions private def render_exception_with_template(env, exception) env['exception'] = exception body = ErrorsController.action(rescue_responses[exception.class.name]).call(env) log_error(exception) env.delete 'exception' body rescue Exception => e log_error(e) render_exception_without_template(env, exception) end alias_method_chain :render_exception, :template end end 
  • Create a view for each of the errors in ErrorsController::ERRORS (i.e. app / views / errors / not_found.html.erb, etc.).

I do not claim that this is the best method, but it still served me well (you can easily add pages for new errors, configure how and what you want to display for each error separately).

+1
source

All Articles