Module: Prosody::ErrorClassification

Included in:
EventHandler
Defined in:
lib/prosody/handler.rb

Overview

Mixin providing class-level methods to wrap instance methods so that specified exceptions are re-wrapped as PermanentError or TransientError.

Examples:

class MyHandler < Prosody::EventHandler
  extend Prosody::ErrorClassification

  # Treat TypeError as permanent (no retry)
  permanent :on_message, TypeError

  # Treat JSON::ParserError as transient (retryable)
  transient :on_message, JSON::ParserError

  def on_message(context, message)
    # Process the message...
  end
end

Instance Method Summary collapse

Instance Method Details

#permanent(method_name, *exception_classes) ⇒ void

This method returns an undefined value.

Wraps the given instance method so that specified exception types are caught and re-raised as Prosody::PermanentError.

Parameters:

  • method_name (Symbol)

    the name of the method to wrap

  • exception_classes (Class<Exception>)

    one or more Exception subclasses to catch

Raises:

  • (ArgumentError)

    if no exception classes given

  • (NameError)

    if method_name is not defined on this class or its ancestors



75
76
77
# File 'lib/prosody/handler.rb', line 75

def permanent(method_name, *exception_classes)
  wrap_errors(method_name, exception_classes, PermanentError)
end

#transient(method_name, *exception_classes) ⇒ void

This method returns an undefined value.

Wraps the given instance method so that specified exception types are caught and re-raised as Prosody::TransientError.

Parameters:

  • method_name (Symbol)

    the name of the method to wrap

  • exception_classes (Class<Exception>)

    one or more Exception subclasses to catch

Raises:

  • (ArgumentError)

    if no exception classes given

  • (NameError)

    if method_name is not defined on this class or its ancestors



87
88
89
# File 'lib/prosody/handler.rb', line 87

def transient(method_name, *exception_classes)
  wrap_errors(method_name, exception_classes, TransientError)
end