Class: ExceptionHandler
- Inherits:
-
Object
- Object
- ExceptionHandler
- Defined in:
- lib/active_job_exception_handler.rb
Defined Under Namespace
Classes: ExceptionContext
Constant Summary collapse
- RetryableError =
Class.new(StandardError)
- TYPES =
%i[ignorables retryables unretryables].freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #add(error, type) ⇒ Object
- #error? ⇒ Boolean
-
#initialize(exception_context:, rescue_retryable_errors:, exception_processors: [ExceptionHandlerStatsdProcessor.new, ExceptionHandlerActionableFaultProcessor.new], logger: ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))) ⇒ ExceptionHandler
constructor
A new instance of ExceptionHandler.
- #process! ⇒ Object
Constructor Details
#initialize(exception_context:, rescue_retryable_errors:, exception_processors: [ExceptionHandlerStatsdProcessor.new, ExceptionHandlerActionableFaultProcessor.new], logger: ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))) ⇒ ExceptionHandler
Returns a new instance of ExceptionHandler.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_job_exception_handler.rb', line 11 def initialize(exception_context:, rescue_retryable_errors:, exception_processors: [ExceptionHandlerStatsdProcessor.new, ExceptionHandlerActionableFaultProcessor.new], logger: ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))) @exception_context = exception_context @exception_processors = exception_processors @rescue_retryable_errors = rescue_retryable_errors @logger = logger @error = nil @ignorables = [] @retryables = [Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED] @unretryables = [] end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/active_job_exception_handler.rb', line 9 def error @error end |
Instance Method Details
#add(error, type) ⇒ Object
26 27 28 29 |
# File 'lib/active_job_exception_handler.rb', line 26 def add(error, type) fail(StandardError, "Invalid error category: #{type}.") unless TYPES.include?(type) public_send(type) << error end |
#error? ⇒ Boolean
31 32 33 |
# File 'lib/active_job_exception_handler.rb', line 31 def error? error.present? end |
#process! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_job_exception_handler.rb', line 35 def process! yield if block_given? rescue *ignorables => error handle_ignorable(error) rescue *retryables => error handle_retryable(error) rescue *unretryables => error handle_unretryable(error) rescue StandardError => error handle_unknown(error) end |