Skip to content

Instantly share code, notes, and snippets.

@3014zhangshuo
Last active July 31, 2018 23:51
Show Gist options
  • Save 3014zhangshuo/70a4dc24d56d335d6af1fbb80eeca84d to your computer and use it in GitHub Desktop.
Save 3014zhangshuo/70a4dc24d56d335d6af1fbb80eeca84d to your computer and use it in GitHub Desktop.
rails controller exception handler
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