Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render 500 page in rescue_from

I would like to send e-mail when having an exception in my application and render the regular 500 page. I could not find how to perform the 500 page render:

class ApplicationController < ActionController::Base
  rescue_from StandardError do
     send_email_of_error
     # what goes here? 
  end

  ...
end
like image 762
mbdev Avatar asked Dec 12 '22 04:12

mbdev


2 Answers

Raising the exception again will likely to what you want:

rescue_from StandardError do |exception|
  send_email_of_error
  raise exception
end

You could also call render to render your own page, the docs have an example doing this.

But why reinvent the wheel? The exception notifier gem already does this and is customizable and tested.

like image 79
Andrew Marshall Avatar answered Dec 15 '22 01:12

Andrew Marshall


This is an approach that maybe fits your needs:

class ApplicationController < ActionController::Base
  rescue_from Exception, :with => :render_500

  def render_500(exception)
    @exception = exception
    render :template => "shared/500.html", :status => 500
  end
end
like image 33
awenkhh Avatar answered Dec 14 '22 23:12

awenkhh