Created
November 14, 2009 16:16
-
-
Save lfittl/234600 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
| def refresh_feed | |
| # .. | |
| begin | |
| # .. | |
| rescue => e | |
| Exceptional.log_frontend(e, self, request, params.merge(:feed_id => params[:id])) | |
| end | |
| end |
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
| module Exceptional | |
| module Api | |
| def safe_session(session_data) | |
| sanitize_hash(session_data.to_hash) | |
| end | |
| def log_failsafe(exception, env) | |
| request = ActionController::Request.new(env) | |
| unless RAILS_ENV == 'production' | |
| SOUP_LOGGER.info "Caught failsafe exception #{exception.message} on #{request.url}\n params: #{request.params.inspect}\n stacktrace:\n #{exception.backtrace.join "\n "}" | |
| return | |
| end | |
| Exceptional.log! "Handling #{exception.message}", 'info' | |
| e = parse(exception) | |
| e.framework = "rails" | |
| e.application_root = Exceptional.application_root | |
| e.occurred_at = Time.now.strftime("%Y%m%d %H:%M:%S %Z") | |
| e.url = request.url | |
| e.environment = safe_environment(request) | |
| e.session = safe_session(env['rack.session'].to_hash) rescue nil | |
| e.parameters = sanitize_hash(request.params.to_hash) | |
| post(e) | |
| rescue Exception => exception | |
| Exceptional.log! "Error preparing exception data." | |
| Exceptional.log! exception.message | |
| Exceptional.log! exception.backtrace.join("\n"), 'debug' | |
| end | |
| def log_frontend(exception, controller, request, params) | |
| unless RAILS_ENV == 'production' | |
| SOUP_LOGGER.info "Caught frontend exception #{exception.message} on #{request.url}\n params: #{params.inspect}\n stacktrace:\n #{exception.backtrace.join "\n "}" | |
| return | |
| end | |
| Exceptional.handle(exception, controller, request, params) | |
| end | |
| def log_backend(location, exception, params) | |
| unless RAILS_ENV == 'production' | |
| SOUP_LOGGER.info "Caught backend exception #{exception.message}\n params: #{params.inspect}\n stacktrace:\n #{exception.backtrace.join "\n "}" | |
| return | |
| end | |
| Exceptional.log! "Handling #{exception.message}", 'info' | |
| e = parse(exception) | |
| e.application_root = Exceptional.application_root | |
| e.occurred_at = Time.now.strftime("%Y%m%d %H:%M:%S %Z") | |
| e.controller_name = location | |
| e.parameters = params.to_hash | |
| post(e) | |
| rescue Exception => exception | |
| Exceptional.log! "Error preparing exception data." | |
| Exceptional.log! exception.message | |
| Exceptional.log! exception.backtrace.join("\n") | |
| end | |
| end | |
| end | |
| # Exceptional integration into failsafe handler | |
| class ActionController::Failsafe | |
| def call(env) | |
| @app.call(env) | |
| rescue Exception => exception | |
| # Reraise exception in test environment | |
| if defined?(Rails) && Rails.env.test? | |
| raise exception | |
| else | |
| Exceptional.log_failsafe(exception, env) | |
| failsafe_response(exception) | |
| end | |
| end | |
| end |
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
| def perform_import | |
| # .. | |
| begin | |
| # .. | |
| rescue Exception => e | |
| Exceptional.log_backend('Feed importer', e, :feed_id => id, :feed_url => self.url, :feed_type => self.class.to_s) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment