Sha256: 1d559f648118412bbae8c65b0f8ea9d25f11cd126a1928822d33e54da242929c

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 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, :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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.20 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.19 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.18 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.17 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.16 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.15 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb