Sha256: 1fcdad455aea0224e3814812019e1a97333a9119c7a36ffac086fda97939ec61

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

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

    private

    def interrupted?(err = exception)
      interrupt_errors.any? {|klass| err.is_a?(klass)}
    end

    def error_raised?
      exception && !interrupted?
    end

    def rescued
      yield
    rescue StandardError => err
      self.exception ||= err
      log(:error) { err.patch_full_message }
    end

    def with_error_handling
      @exception = nil
      yield
    rescue SystemExit => sext
      @exception = sext
      exit sext.status
    rescue *interrupt_errors => int
      @exception = int
      raise
    rescue SystemStackError
      puts $! # rubocop:disable Style/SpecialGlobalVars
      puts caller[0..100]
      raise
    rescue StandardError, SignalException => err
      @exception = err
      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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eco-helpers-3.0.10 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.9 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.8 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.7 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb