forked from stackify/stackify-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.py
More file actions
74 lines (60 loc) · 2.15 KB
/
error.py
File metadata and controls
74 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
70
71
72
73
74
import traceback
import time
import sys
from stackify.formats import JSONObject
class ErrorItem(JSONObject):
def __init__(self):
self.Message = None # exception message
self.ErrorType = None # exception class name
self.ErrorTypeCode = None
self.Data = None # custom data
self.SourceMethod = None
self.StackTrace = [] # array of TraceFrames
self.InnerError = None # cause?
def load_stack(self, exc_info=None):
if not exc_info:
type_, value, tb = sys.exc_info()
else:
type_, value, tb = exc_info
stacks = traceback.extract_tb(tb)
self.ErrorType = type_.__name__
self.Message = str(value)
self.SourceMethod = stacks[-1][2]
for filename, lineno, method, text in reversed(stacks):
self.StackTrace.append(TraceFrame(filename, lineno, method))
class TraceFrame(JSONObject):
def __init__(self, filename, lineno, method):
self.CodeFileName = filename
self.LineNum = lineno
self.Method = method
class WebRequestDetail(JSONObject):
def __init__(self):
self.UserIPAddress = None
self.HttpMethod = None
self.RequestProtocol = None
self.RequestUrl = None
self.RequestUrlRoot = None
self.ReferralUrl = None
self.Headers = {}
self.Cookies = {}
self.QueryString = {}
self.PostData = {}
self.SessionData = {}
self.PostDataRaw = None
self.MVCAction = None
self.MVCController = None
self.MVCArea = None
class StackifyError(JSONObject):
def __init__(self):
self.EnvironmentDetail = None # environment detail object
self.OccurredEpochMillis = None
self.Error = None # ErrorItem object
self.WebRequestDetail = None # WebRequestDetail object
self.CustomerName = None
self.UserName = None
def load_exception(self, exc_info=None):
self.Error = ErrorItem()
self.Error.load_stack(exc_info)
def from_record(self, record):
self.load_exception(record.exc_info)
self.OccurredEpochMillis = int(record.created * 1000)