lib/eco/api/usecases/graphql/helpers/base/error_handling.rb in eco-helpers-3.0.14 vs lib/eco/api/usecases/graphql/helpers/base/error_handling.rb in eco-helpers-3.0.15
- old
+ new
@@ -1,11 +1,11 @@
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
+ attr_reader :exception, :exiting
private
def exception_already_captured?(err)
err == exception
@@ -17,34 +17,45 @@
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 SystemExit => sext
- @exception = sext
- exit sext.status
- rescue *interrupt_errors => int
+ 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
- rescue StandardError, SignalException => err
- @exception = err
raise
end
def interrupt_errors
return @interrupt_errors if @interrupt_errors