forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebErrorParser.ts
More file actions
53 lines (43 loc) · 1.68 KB
/
WebErrorParser.ts
File metadata and controls
53 lines (43 loc) · 1.68 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
import { IError } from '../models/IError';
import { IParameter } from '../models/IParameter';
import { IErrorParser } from 'IErrorParser';
import { IStackFrame } from '../models/IStackFrame';
import { EventPluginContext } from '../plugins/EventPluginContext';
export class WebErrorParser implements IErrorParser {
public parse(context:EventPluginContext, exception:Error): void {
var stackTrace:TraceKit.StackTrace = !!context.contextData['@@_TraceKit.StackTrace']
? context.contextData['@@_TraceKit.StackTrace']
: TraceKit.computeStackTrace(exception, 25);
if (!stackTrace) {
throw new Error('Unable to parse the exceptions stack trace.');
}
var error:IError = {
type: stackTrace.name,
message: stackTrace.message || exception.message,
stack_trace: this.getStackFrames(context, stackTrace.stack || [])
};
context.event.data['@error'] = error;
}
private getStackFrames(context:EventPluginContext, stackFrames:TraceKit.StackFrame[]): IStackFrame[] {
var frames:IStackFrame[] = [];
for (var index = 0; index < stackFrames.length; index++) {
var frame = stackFrames[index];
frames.push({
name: frame.func,
parameters: this.getParameters(frame.args),
file_name: frame.url,
line_number: frame.line,
column: frame.column
});
}
return frames;
}
private getParameters(parameters:string|string[]): IParameter[] {
var params:string[] = (typeof parameters === 'string' ? [parameters] : parameters) || [];
var result:IParameter[] = [];
for (var index = 0; index < params.length; index++) {
result.push({ name: params[index] })
}
return result;
}
}