Exception: Stackify::StackifiedError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/stackify/error.rb

Constant Summary collapse

CONTEXT_PROPERTIES =
{ 'user' => 'current_user'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ex, error_binding) ⇒ StackifiedError

Returns a new instance of StackifiedError.



13
14
15
16
17
18
19
# 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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/stackify/error.rb', line 11

def context
  @context
end

#exceptionObject (readonly)

Returns the value of attribute exception.



11
12
13
# File 'lib/stackify/error.rb', line 11

def exception
  @exception
end

Instance Method Details

#backtraceObject



21
22
23
# File 'lib/stackify/error.rb', line 21

def backtrace
  Stackify::Backtrace.stacktrace @exception.backtrace
end

#error_typeObject



33
34
35
36
37
38
39
# 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

#messageObject



29
30
31
# File 'lib/stackify/error.rb', line 29

def message
  @exception.message
end

#source_methodObject



25
26
27
# File 'lib/stackify/error.rb', line 25

def source_method
  Stackify::Backtrace.method_name @exception.try{ |e| e.backtrace[0] }
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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