Module: MimeActor::Rescue

Extended by:
ActiveSupport::Concern
Includes:
Validator
Included in:
Stage
Defined in:
lib/mime_actor/rescue.rb

Overview

# MimeActor Rescue

Simillar to ‘ActionController::Rescue` but with additional filtering logic on `action`/`format`.

Examples:

Rescue RuntimeError when raised for any action with ‘json` format

rescue_act_from RuntimeError, format: :json, with: :handle_json_error

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#rescue_actor(error, action:, format:, visited: []) ⇒ Object

Resolve the error provided with the registered handlers.

The handled error will be returned to indicate successful handling.

Parameters:

  • error

    the error instance to rescue

  • action

    the ‘action` filter

  • format

    the ‘format` filter

  • visited (defaults to: [])

    the errors to skip after no rescue handler matched the filter



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mime_actor/rescue.rb', line 75

def rescue_actor(error, action:, format:, visited: [])
  return if visited.include?(error)

  visited << error
  rescuer = find_rescuer(error, format: format, action: action)
  if (dispatch = MimeActor::Dispatcher.build(rescuer, error, format, action))
    dispatch.call(self)
    error
  elsif error&.cause
    rescue_actor(error.cause, format: format, action: action, visited: visited)
  end
end