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
41 lines (35 loc) · 1.31 KB
/
NodeErrorParser.ts
File metadata and controls
41 lines (35 loc) · 1.31 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
import { IError } from '../models/IError';
import { IStackFrame } from '../models/IStackFrame';
import { EventPluginContext } from '../plugins/EventPluginContext';
import { IErrorParser } from './IErrorParser';
import nodestacktrace = require('stack-trace');
export class NodeErrorParser implements IErrorParser {
public parse(context: EventPluginContext, exception: Error): IError {
function getStackFrames(stackFrames: any[]): IStackFrame[] {
const frames: IStackFrame[] = [];
for (const frame of stackFrames) {
frames.push({
name: frame.getMethodName() || frame.getFunctionName(),
// parameters: frame.args,
file_name: frame.getFileName(),
line_number: frame.getLineNumber() || 0,
column: frame.getColumnNumber() || 0,
declaring_type: frame.getTypeName(),
data: {
is_native: frame.isNative() || (!!frame.filename && frame.filename[0] !== '/' && frame.filename[0] !== '.')
}
});
}
return frames;
}
if (!nodestacktrace) {
throw new Error('Unable to load the stack trace library.');
}
const stackFrames = nodestacktrace.parse(exception) || [];
return {
type: exception.name,
message: exception.message,
stack_trace: getStackFrames(stackFrames)
};
}
}