forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeErrorParser.ts
More file actions
50 lines (42 loc) · 1.72 KB
/
NodeErrorParser.ts
File metadata and controls
50 lines (42 loc) · 1.72 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
import { IError } from '../models/IError';
import { IErrorParser } from 'IErrorParser';
import { IStackFrame } from '../models/IStackFrame';
import { EventPluginContext } from '../plugins/EventPluginContext';
import nodestacktrace = require('stack-trace');
export class NodeErrorParser implements IErrorParser {
public parse(context:EventPluginContext, exception:Error): Promise<IError> {
if (!nodestacktrace) {
context.cancel = true;
return Promise.reject(new Error('Unable to load the stack trace library. This exception will be discarded.'))
}
var stackFrames = nodestacktrace.parse(exception);
if (!stackFrames || stackFrames.length === 0) {
context.cancel = true;
return Promise.reject(new Error('Unable to parse the exceptions stack trace. This exception will be discarded.'))
}
var error:IError = {
message: exception.message,
stack_trace: this.getStackFrames(context, stackFrames || [])
};
context.event.data['@error'] = error;
return Promise.resolve();
}
private getStackFrames(context:EventPluginContext, stackFrames:any[]): IStackFrame[] {
var frames:IStackFrame[] = [];
for (var index = 0; index < stackFrames.length; index++) {
var frame = stackFrames[index];
frames.push({
name: frame.getMethodName() || frame.getFunctionName(),
//parameters: stackFrames[index].args,
file_name: frame.getFileName(),
line_number: frame.getLineNumber(),
column: frame.getColumnNumber(),
declaring_type: frame.getTypeName(),
data: {
is_native: frame.isNative() || (!!frame.filename && frame.filename[0] !== '/' && frame.filename[0] !== '.')
}
});
}
return frames;
}
}