Commit 5e7f599f3f416132fc1bea5c7fff49fa987459af

Authored by Nathan Broadbent
1 parent 0e8f9ea0
Exists in master and in 1 other branch production

Changed default handling of Errbit's internal errors. The default is now to save…

… them locally, in an automatically created App named "Self.Errbit". Errbit can still be configured to send errors to our central Errbit instance, but we were getting too many spam errors caused by users (e.g. invalid email address). Most developers will prefer to see Errbit's errors themselves anyway. I will write up a HowTo on how developers can configure a GitHub issue tracker for 'Self.Errbit', in order to send us error reports.
config/config.example.yml
... ... @@ -46,10 +46,10 @@ user_has_username: false
46 46  
47 47  
48 48 # Configure tracking for Errbit's own internal errors.
49   -# There is a central Errbit instance running on heroku,
50   -# and other Errbit instances will send their errors there by default.
51   -# Please leave this section commented if you don't need to override the defaults.
52   -# -------------------------------------------------------------------------------
  49 +# By default, Errbit will log it's own errors to an internal App named 'Self.Errbit'.
  50 +# The 'Self.Errbit' app will be automatically created whenever the first error happens.
  51 +# Uncomment this section if you would rather send error reports to our central Errbit instance.
  52 +# ---------------------------------------------------------------------------------------------
53 53 #report_self_errors: true
54 54 #self_errors_host: errbit-central.heroku.com
55 55 #self_errors_port: 80
... ...
config/initializers/hoptoad.rb
1   -if Rails.env.production? && Errbit::Config.report_self_errors.to_s != "false"
2   - HoptoadNotifier.configure do |config|
3   - config.api_key = Errbit::Config.self_errors_api_key || "11e5ce322856e540481e6a0789893179"
4   - config.host = Errbit::Config.self_errors_host || "errbit-central.heroku.com"
5   - config.port = Errbit::Config.self_errors_port || 80
6   - config.secure = config.port == 443
7   - end
  1 +HoptoadNotifier.configure do |config|
  2 + config.api_key = Errbit::Config.self_errors_api_key || "11e5ce322856e540481e6a0789893179"
  3 + config.host = Errbit::Config.self_errors_host || "errbit-central.heroku.com"
  4 + config.port = Errbit::Config.self_errors_port || 80
  5 + config.secure = config.port == 443
8 6 end
9 7  
... ...
config/initializers/overrides.rb
1   -require Rails.root.join('lib/overrides/mongoid/relations/builder.rb')
2   -require Rails.root.join('lib/overrides/devise/failure_app.rb')
  1 +require Rails.root.join('lib/overrides/mongoid/relations/builder')
  2 +require Rails.root.join('lib/overrides/devise/failure_app')
  3 +require Rails.root.join('lib/overrides/hoptoad_notifier/hoptoad_notifier')
3 4  
... ...
lib/overrides/hoptoad_notifier/hoptoad_notifier.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +# Override the 'hoptoad_notifier' gem's 'send_notice' method for internal errors.
  2 +# Find or create a 'Self.Errbit' app, and save the error internally
  3 +# unless errors should be sent to a different Errbit instance.
  4 +
  5 +HoptoadNotifier.module_eval do
  6 + class << self
  7 + private
  8 + def send_notice_with_internal(notice)
  9 + if Errbit::Config.report_self_errors.to_s == "true"
  10 + # Using the original method, send notice to a different Errbit instance.
  11 + send_notice_without_internal(notice)
  12 + else
  13 + # Otherwise, if we are not in a development environment, log the error internally.
  14 + if configuration.public?
  15 + begin
  16 + app = App.find_or_initialize_by(:name => "Self.Errbit")
  17 + if app.new?
  18 + app.github_url = "https://github.com/errbit/errbit.git"
  19 + app.save!
  20 + end
  21 + notice.send("api_key=", app.api_key)
  22 + # Create notice internally.
  23 + # 'to_xml ~> from_xml' provides a data bridge between hoptoad_notifier and Errbit.
  24 + ::Notice.from_xml(notice.to_xml)
  25 + logger.info "Internal error was logged to 'Self.Errbit' app."
  26 + rescue
  27 + logger.error "-- Errbit crashed while processing an internal error!" if logger
  28 + end
  29 + end
  30 + end
  31 + end
  32 + alias_method_chain :send_notice, :internal
  33 + end
  34 +end
  35 +
... ...