Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add named exception notifier for Honeybadger #61

Merged
merged 1 commit into from

2 participants

Cory Forsyth Darcy Laycock
Cory Forsyth

This adds a named exception notifier callback for :honeybadger and also adds a test that a custom exception notifier callback gets called.

Darcy Laycock Sutto merged commit 8ff152f into from
Darcy Laycock
Owner

Looks excellent - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2013
  1. Cory Forsyth
This page is out of date. Refresh to see the latest.
11 lib/rocket_pants/base.rb
View
@@ -40,6 +40,15 @@ class Base < ActionController::Metal
rescue LoadError => e
end
+ # If possible, include Honeybadger methods in the Rails controller
+ begin
+ require 'honeybadger'
+ require 'honeybadger/rails/controller_methods'
+ MODULES << Honeybadger::Rails::ControllerMethods
+ rescue LoadError => e
+ end
+
+
MODULES.each do |mixin|
include mixin
end
@@ -56,4 +65,4 @@ class Base < ActionController::Metal
def self.helper_method(*); end
end
-end
+end
7 lib/rocket_pants/controller/rescuable.rb
View
@@ -16,6 +16,11 @@ module Rescuable
unless c.send(:airbrake_local_request?)
c.error_identifier = Airbrake.notify(e, c.send(:airbrake_request_data))
end
+ },
+ :honeybadger => lambda { |controller, exception, request|
+ if controller.respond_to?(:notify_honeybadger, true)
+ controller.send(:notify_honeybadger, exception)
+ end
}
}
@@ -64,4 +69,4 @@ def process_action(*args)
end
end
-end
+end
109 spec/rocket_pants/controller/error_handling_spec.rb
View
@@ -7,51 +7,59 @@
context 'error handler functions' do
- around :each do |test|
- with_config :pass_through_errors, false, &test
- end
+ context 'when pass_through_errors is false' do
+ around :each do |test|
+ with_config :pass_through_errors, false, &test
+ end
- it 'should allow you to set the error handle from a named type' do
- controller_class.exception_notifier_callback.should == controller_class::DEFAULT_NOTIFIER_CALLBACK
- controller_class.use_named_exception_notifier :airbrake
- controller_class.exception_notifier_callback.should_not == controller_class::DEFAULT_NOTIFIER_CALLBACK
- controller_class.exception_notifier_callback.should == controller_class::NAMED_NOTIFIER_CALLBACKS[:airbrake]
- controller_class.use_named_exception_notifier :nonexistant
- controller_class.exception_notifier_callback.should == controller_class::DEFAULT_NOTIFIER_CALLBACK
- end
+ it 'should allow you to set the error handle from a named type' do
+ controller_class.exception_notifier_callback.should == controller_class::DEFAULT_NOTIFIER_CALLBACK
- it 'should include the error identifier in the response if set' do
- controller_class.exception_notifier_callback = lambda do |controller, exception, req|
- controller.error_identifier = 'my-test-identifier'
- end
- get :test_error
- content[:error_identifier].should == 'my-test-identifier'
- end
+ controller_class.use_named_exception_notifier :airbrake
+ controller_class.exception_notifier_callback.should_not == controller_class::DEFAULT_NOTIFIER_CALLBACK
+ controller_class.exception_notifier_callback.should == controller_class::NAMED_NOTIFIER_CALLBACKS[:airbrake]
- it 'should throw the correct error for invalid api versions' do
- get :echo, {}, :version => '3'
- content['error'].should == 'invalid_version'
- end
+ controller_class.use_named_exception_notifier :honeybadger
+ controller_class.exception_notifier_callback.should_not == controller_class::DEFAULT_NOTIFIER_CALLBACK
+ controller_class.exception_notifier_callback.should == controller_class::NAMED_NOTIFIER_CALLBACKS[:honeybadger]
- it 'should return the correct output for a manually thrown error' do
- get :demo_exception
- content['error'].should == 'throttled'
- content['error_description'].should be_present
- end
+ controller_class.use_named_exception_notifier :nonexistent
+ controller_class.exception_notifier_callback.should == controller_class::DEFAULT_NOTIFIER_CALLBACK
+ end
- it 'should stop the flow if you raise an exception' do
- get :premature_termination
- content['error'].should be_present
- content['error_description'].should be_present
- content['response'].should be_nil
- end
+ it 'should include the error identifier in the response if set' do
+ controller_class.exception_notifier_callback = lambda do |controller, exception, req|
+ controller.error_identifier = 'my-test-identifier'
+ end
+ get :test_error
+ content[:error_identifier].should == 'my-test-identifier'
+ end
- it 'should use i18n for error messages' do
- with_translations :rocket_pants => {:errors => {:throttled => 'Oh noes, a puddle.'}} do
+ it 'should throw the correct error for invalid api versions' do
+ get :echo, {}, :version => '3'
+ content['error'].should == 'invalid_version'
+ end
+
+ it 'should return the correct output for a manually thrown error' do
get :demo_exception
+ content['error'].should == 'throttled'
+ content['error_description'].should be_present
+ end
+
+ it 'should stop the flow if you raise an exception' do
+ get :premature_termination
+ content['error'].should be_present
+ content['error_description'].should be_present
+ content['response'].should be_nil
+ end
+
+ it 'should use i18n for error messages' do
+ with_translations :rocket_pants => {:errors => {:throttled => 'Oh noes, a puddle.'}} do
+ get :demo_exception
+ end
+ content['error'].should == 'throttled'
+ content['error_description'].should == 'Oh noes, a puddle.'
end
- content['error'].should == 'throttled'
- content['error_description'].should == 'Oh noes, a puddle.'
end
end
@@ -199,4 +207,29 @@ def error.context; {:metadata => {:hello => 'There'}} ; end
end
-end
+ describe 'custom exception_notifier_callback' do
+ before do
+ @called_exception_notifier_callback = false
+ end
+
+ let(:custom_exception_notifier_callback) {
+ lambda {|c,e,r| @called_exception_notifier_callback = true }
+ }
+
+ before :each do
+ # Replace it with a new error mapping.
+ stub(controller_class).error_mapping { error_mapping }
+ stub.instance_of(controller_class).error_mapping { error_mapping }
+ controller_class.exception_notifier_callback = custom_exception_notifier_callback
+ end
+
+ it "should call the custom exception notifier callback" do
+ with_config :pass_through_errors, false do
+ get :test_error
+ @called_exception_notifier_callback.should be_true
+ end
+ end
+
+ end
+
+end
Something went wrong with that request. Please try again.