Last active
July 31, 2018 23:51
-
-
Save 3014zhangshuo/70a4dc24d56d335d6af1fbb80eeca84d to your computer and use it in GitHub Desktop.
rails controller exception handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found | |
private | |
def record_not_found | |
render plain "404 not found", status: 404 | |
end | |
end | |
class ApplicationController < ActionController::Base | |
rescue_from Exception do |exception| | |
if Rails.env.production? or Rails.env.staging? | |
and ![ActionController::RoutingError].include?(exception.class) | |
Rails.logger.info "send exception email!" | |
SystemMailer.web_exception_notify(AppConfig.app_notify_receiver, { | |
request: request, | |
params: params, | |
user: current_user, | |
exception: exception | |
}).deliver_now | |
redirect_to '/?response_code=505' | |
else | |
raise exception | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment