Module: Servus::Support::Rescuer::ClassMethods
- Defined in:
- lib/servus/support/rescuer.rb
Overview
Class methods for rescue_from
Instance Method Summary collapse
-
#rescue_from(*errors, use: Servus::Support::Errors::ServiceError) {|exception| ... } ⇒ Object
Configures automatic error handling for the service.
Instance Method Details
#rescue_from(*errors, use: Servus::Support::Errors::ServiceError) {|exception| ... } ⇒ Object
Configures automatic error handling for the service.
Declares which exception classes should be automatically rescued and converted to failure responses. Without a block, exceptions are wrapped in the specified ServiceError type with a formatted message including the original exception details.
When a block is provided, it receives the exception and must return either
success(data) or failure(message, type:) to create the response.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/servus/support/rescuer.rb', line 125 def rescue_from(*errors, use: Servus::Support::Errors::ServiceError, &block) config = { errors: errors, error_type: use, handler: block } # Add to rescuable_configs array self.rescuable_configs = rescuable_configs + [config] end |