Created
June 8, 2012 08:57
-
-
Save vrinek/2894591 to your computer and use it in GitHub Desktop.
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 StaticsController < ActionController::Base | |
| def render_404 | |
| if real_404? | |
| send_detailed_disaster_mail(request) | |
| end | |
| respond_to do |format| | |
| format.json do | |
| render json: "", status: 404 | |
| end | |
| format.js do | |
| render text: "", status: 404 | |
| end | |
| format.html do | |
| render template: "statics/404", status: 404, layout: 'application' | |
| end | |
| end | |
| end | |
| private | |
| def real_404? | |
| # code to reject known 404s (like browser bugs) | |
| end | |
| def send_detailed_disaster_mail(req) | |
| message = "#{req.method}: #{req.url}" | |
| subject = "[404] RoutingError #{message}" | |
| max = req.env.keys.map(&:size).max | |
| req.env.each do |key, value| | |
| message << "\n#{key.rjust(max)} : #{value}" | |
| end | |
| if Rails.env.development? | |
| logger.debug message | |
| else | |
| ::Mailer.disaster(subject, message).deliver | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment