Class: CoAspects::Aspects::RescueAndNotifyAspect
- Inherits:
-
Aspector::Base
- Object
- Aspector::Base
- CoAspects::Aspects::RescueAndNotifyAspect
- Defined in:
- lib/co_aspects/aspects/rescue_and_notify_aspect.rb
Overview
Rescues any error and notifies NewRelic about it, without raising it again.
If the exception responds to ‘newrelic_opts` then the return value will be used as the noticed error options.
Important: The class ‘CoAspects::Aspects::RescueAndNotifyError` can be used as parent to custom error classes.
Important: If CoAspects::Aspects::RescueAndNotifyAspect.enable_test_mode! is executed, then instead of calling NewRelic, it will raise the exception as if this aspect didn’t exist. It’s to be used by tests, to see exceptions being raised inside ‘_rescue_and_notify` annotated methods.
Enabling test mode is not thread safe!
Examples
class MyClass
aspects_annotations!
_rescue_and_notify
def perform_with_error
fail 'Error'
end
_rescue_and_notify
def perform_without_error
:success
end
end
MyClass.new.perform_with_error
# NewRelic::Agent.notify_error(...)
# => nil
MyClass.new.perform_without_error
# => :success
Class Method Summary collapse
Class Method Details
.disable_test_mode! ⇒ Object
54 55 56 |
# File 'lib/co_aspects/aspects/rescue_and_notify_aspect.rb', line 54 def disable_test_mode! @test_mode = false end |
.enable_test_mode! ⇒ Object
50 51 52 |
# File 'lib/co_aspects/aspects/rescue_and_notify_aspect.rb', line 50 def enable_test_mode! @test_mode = true end |
.test_mode ⇒ Object
46 47 48 |
# File 'lib/co_aspects/aspects/rescue_and_notify_aspect.rb', line 46 def test_mode !!@test_mode end |