module ExceptionTransformer::Reportable
Include this module when declaring an exception class to add the `reportable?` flag to individual exceptions. The presence of this flag can then be checked when capturing exceptions to send to a crash reporter.
@example Conditionally reporting exceptions
class MyError < StandardError include ExceptionTransformer::ReportableException end begin # do something that may fail rescue MyError => e CrashReport.new(e) if e.reportable? end
This flag can be set at the instance level with `mark_reportable!`. Alternatively, the class method `as_reportable` returns a subclass for which `reportable?` is true when raised.
Public Class Methods
included(base)
click to toggle source
# File lib/exception_transformer/reportable.rb, line 24 def self.included(base) raise TypeError, "#{base} is not a type of Exception" unless base <= Exception base.extend ClassMethods end
Public Instance Methods
mark_reportable!()
click to toggle source
# File lib/exception_transformer/reportable.rb, line 76 def mark_reportable! @reportable = true end
reportable?()
click to toggle source
# File lib/exception_transformer/reportable.rb, line 72 def reportable? @reportable ||= false end