Module: Servus::Support::Rescuer

Included in:
Base
Defined in:
lib/servus/support/rescuer.rb

Overview

Provides automatic error handling for services via ClassMethods#rescue_from.

This module enables services to declare which exceptions should be automatically caught and converted to failure responses, eliminating repetitive rescue blocks.

Examples:

Basic usage

class MyService < Servus::Base
  rescue_from Net::HTTPError, Timeout::Error,
    use: Servus::Support::Errors::ServiceUnavailableError

  def call
    make_external_api_call  # May raise Net::HTTPError
  end
end

See Also:

Defined Under Namespace

Modules: CallOverride, ClassMethods Classes: BlockContext

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets up error rescue functionality when included.



26
27
28
29
30
# File 'lib/servus/support/rescuer.rb', line 26

def self.included(base)
  base.class_attribute :rescuable_configs, default: []
  base.singleton_class.prepend(CallOverride)
  base.extend(ClassMethods)
end