Sha256: 06c47dd83526179b23a7efd3c8c58e66703fb1eeb8ffb832ce5681a7abc6e6e2

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 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 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 rescued
      yield
    rescue StandardError => err
      self.exception ||= err

      unless exception_already_captured?(err)
        log(:error) { err.patch_full_message }
      end
    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.14 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.13 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.12 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
eco-helpers-3.0.11 lib/eco/api/usecases/graphql/helpers/base/error_handling.rb