Class: Findbug::Capture::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/findbug/capture/exception_handler.rb

Overview

ExceptionHandler provides the public API for capturing exceptions.

This is used by:

  • Findbug.capture_exception (public API)

  • Manual captures in user code

It’s separate from Middleware/Subscriber because those are automatic. This is for explicit, manual captures.

WHEN TO USE MANUAL CAPTURE

  1. Handled exceptions you still want to track:

    begin

    external_api.call
    

    rescue ExternalAPIError => e

    Findbug.capture_exception(e)
    # Handle gracefully...
    

    end

  2. Exceptions in background jobs (if not auto-captured):

    class HardWorker

    def perform
      do_work
    rescue => e
      Findbug.capture_exception(e)
      raise # Re-raise for Sidekiq retry
    end
    

    end

  3. Exceptions with extra context:

    Findbug.capture_exception(e, order_id: order.id, action: “payment”)

Class Method Summary collapse

Class Method Details

.capture(exception, extra_context = {}) ⇒ Object

Capture an exception

Parameters:

  • exception (Exception)

    the exception to capture

  • extra_context (Hash) (defaults to: {})

    additional context for this error



51
52
53
54
55
56
57
58
59
# File 'lib/findbug/capture/exception_handler.rb', line 51

def capture(exception, extra_context = {})
  return unless Findbug.enabled?
  return unless should_capture?(exception)

  event_data = build_event_data(exception, extra_context)
  Storage::RedisBuffer.push_error(event_data)
rescue StandardError => e
  Findbug.logger.error("[Findbug] ExceptionHandler failed: #{e.message}")
end