Class: Mediate::ErrorHandler Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/mediate/error_handler.rb

Overview

This class is abstract.

override #handle to implement.

An abstract base class that handles exceptions raised by request handlers, behaviors, or notification handlers.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handles(exception_class = StandardError, dispatched_class = Mediate::Request, mediator = Mediate.mediator) ⇒ void

This method returns an undefined value.

Registers this to handle exceptions of type exception_class when raised while handling requests or notifications

of type dispatched_class.

Parameters:

  • exception_class (StandardError) (defaults to: StandardError)

    the type of exceptions that this should handle

  • dispatched_class (Class) (defaults to: Mediate::Request)

    the request or notification type (should inherit from Mediate::Request or Mediate::Notification)

  • mediator (Mediate::Mediator) (defaults to: Mediate.mediator)

    the Mediator instance to register on

Raises:

  • (ArgumentError)

    if exception_class is not a StandardError or dispatched_class is not a Request or Notification



23
24
25
# File 'lib/mediate/error_handler.rb', line 23

def self.handles(exception_class = StandardError, dispatched_class = Mediate::Request, mediator = Mediate.mediator)
  mediator.register_error_handler(self, exception_class, dispatched_class)
end

Instance Method Details

#handle(_dispatched, _exception, _state) ⇒ void

This method is abstract.

This method returns an undefined value.

The method to implement to handle exceptions.

Parameters:

  • _dispatched (Mediate::Request, Mediate::Notification)

    the request or notification that was been handled

  • _exception (StandardError)

    the exception that was raised

  • _state (Mediate::ErrorHandlerState)

    the result of handling the current exception– call state.set_as_handled(result) to skip subsequent error handlers and return result (if the exception was thrown while handling a request; notification handlers will not return anything)

Raises:

  • (NoMethodError)


40
41
42
# File 'lib/mediate/error_handler.rb', line 40

def handle(_dispatched, _exception, _state)
  raise NoMethodError, "handle must be implemented"
end