This exception handler get the details of exception and returns a view in development environment and send mail or log in production environment
in application_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception #global excetion handler rescue_from ::Exception ,with: :error_occurred protected def error_occurred(exception) error_details_json={error: exception.message , controller: params['controller'] , action: params['action'] , stacktrace: $ERROR_POSITION , source: $ERROR_INFO }.to_json if Rails.env.development? render json: error_details_json, status: 500 else #Send mail by mailer @i=0 end return end end |