class LambdaErrors::LambdaError

Public Class Methods

new(original_error, classification = 'Function') click to toggle source
Calls superclass method
# File lib/aws_lambda_ric/lambda_errors.rb, line 10
def initialize(original_error, classification = 'Function')
  @error_class = original_error.class.to_s
  @error_type = "#{classification}<#{original_error.class}>"
  @error_message = original_error.message
  @stack_trace = _sanitize_stacktrace(original_error.backtrace_locations)
  super(original_error)
end

Public Instance Methods

runtime_error_type() click to toggle source
# File lib/aws_lambda_ric/lambda_errors.rb, line 18
def runtime_error_type
  if _allowed_error?
    @error_type
  else
    'Function<UserException>'
  end
end
to_lambda_response() click to toggle source
# File lib/aws_lambda_ric/lambda_errors.rb, line 26
def to_lambda_response
  {
      :errorMessage => @error_message,
      :errorType => @error_type,
      :stackTrace => @stack_trace
  }
end

Private Instance Methods

_allowed_error?() click to toggle source
# File lib/aws_lambda_ric/lambda_errors.rb, line 53
def _allowed_error?
  # _aws_sdk_pattern? || _standard_error?
  _standard_error?
end
_aws_sdk_pattern?() click to toggle source

Currently unused, may be activated later.

# File lib/aws_lambda_ric/lambda_errors.rb, line 59
def _aws_sdk_pattern?
  @error_class.match(/Aws(::\w+)*::Errors/)
end
_sanitize_stacktrace(stacktrace) click to toggle source
# File lib/aws_lambda_ric/lambda_errors.rb, line 36
def _sanitize_stacktrace(stacktrace)
  ret = []
  safe_trace = true
  if stacktrace
    stacktrace.first(100).each do |line|
      if safe_trace
        if line.to_s.match(%r{^lib})
          safe_trace = false
        else
          ret << line
        end
      end # else skip
    end
  end
  ret
end
_standard_error?() click to toggle source
# File lib/aws_lambda_ric/lambda_errors.rb, line 63
def _standard_error?
  %w[ArgumentError NoMethodError Exception StandardError NameError LoadError SystemExit SystemStackError].include?(@error_class)
end