class Stackify::StackifiedError

Constants

CONTEXT_PROPERTIES

Attributes

context[R]
exception[R]

Public Class Methods

new(ex, error_binding) click to toggle source
# File lib/stackify/error.rb, line 13
def initialize(ex, error_binding)
  @exception = ex
  @context = {}
  CONTEXT_PROPERTIES.each do |key , value|
    @context[key] = error_binding.eval(value) if error_binding.local_variable_defined?(value.to_sym)
  end
end

Public Instance Methods

backtrace() click to toggle source
# File lib/stackify/error.rb, line 21
def backtrace
  Stackify::Backtrace.stacktrace @exception.backtrace
end
error_type() click to toggle source
# File lib/stackify/error.rb, line 33
def error_type
  if @exception.class.to_s == 'StringException'
    @exception.message.split(" ")[0].to_s
  else
    @exception.class
  end
end
message() click to toggle source
# File lib/stackify/error.rb, line 29
def message
  @exception.message
end
source_method() click to toggle source
# File lib/stackify/error.rb, line 25
def source_method
  Stackify::Backtrace.method_name @exception.try{ |e| e.backtrace[0] }
end
to_h() click to toggle source
# File lib/stackify/error.rb, line 41
def to_h
  env = Stackify::EnvDetails.instance
  data = {
    'OccurredEpochMillis' => Time.now.to_f*1000,
    'Error' => {
      'InnerError' => @exception.try(:cause),
      'StackTrace' => backtrace,
      'Message' => message,
      'ErrorType' => error_type.to_s,
      'ErrorTypeCode' => nil,
      'Data' => {},
      'SourceMethod' => source_method,
    },
    'EnvironmentDetail' => env.auth_info,
    'CustomerName' => 'Customer',
    'UserName' => @context.fetch('user', '')
  }
  web_request_details = env.request_details.try{ |d| d.fetch('webrequest_details', '') }
  if web_request_details.nil?
    data['WebRequestDetail'] = web_request_details
  end

  server_variables = env.request_details.try{ |d| d.fetch('server_variables', '') }
  if server_variables.nil?
    data['ServerVariables'] = server_variables
  end

  data
end