module Eco::API::UseCases::GraphQL::Helpers::Base # Basic stuff you would need in any use case module ErrorHandling include Eco::Language::AuxiliarLogger attr_reader :exception, :exiting private def exception_already_captured?(err) err == exception end def interrupted?(err = exception) interrupt_errors.any? {|klass| err.is_a?(klass)} end def error_raised? exception && !interrupted? end def exiting? @exiting end def exception? error_raised? || exiting? end def rescued yield rescue StandardError => err self.exception ||= err unless exception_already_captured?(err) log(:error) { err.patch_full_message } end rescue SystemExit @exiting = true raise end def with_error_handling @exception = nil yield rescue StandardError, SignalException => err @exception = err raise rescue SystemExit @exiting = true raise rescue *interrupt_errors @exception = int raise rescue SystemStackError puts $! # rubocop:disable Style/SpecialGlobalVars puts caller[0..100] raise end def interrupt_errors return @interrupt_errors if @interrupt_errors errs = [Interrupt] errs << IRB::Abort if Object.const_defined?(:IRB) && IRB.const_defined?(:Abort) @interrupt_errors = errs end end end