module BloodContracts::Core::ExceptionHandling
Concern to wrap matching process with exception handling
@example Defines a type with automatic exception handling in form of types
class JsonType < ::BC::Refined prepend ExceptionHandling def match @context[:parsed_json] = JSON.parse(value) self end end
Public Instance Methods
exception(exc, context: @context)
click to toggle source
Wraps the exception in refinement type
@param exc [Exception] raised exception @option context [Hash] shared context of matching pipeline @return [ExceptionCaught]
# File lib/blood_contracts/core/exception_handling.rb, line 32 def exception(exc, context: @context) ExceptionCaught.new(exc, context: context) end
match()
click to toggle source
Runs the matching process and returns an ExceptionCaught
if StandardError happened inside match call
@return [Refined]
Calls superclass method
# File lib/blood_contracts/core/exception_handling.rb, line 20 def match super rescue StandardError => ex exception(ex) end