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
47 lines (39 loc) · 1.71 KB
/
WebErrorParser.ts
File metadata and controls
47 lines (39 loc) · 1.71 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
import { IError } from '../models/IError';
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): Promise<IError> {
return StackTrace.fromError(exception).then(
(stackFrames: StackTrace.StackFrame[]) => this.processError(context, exception, stackFrames),
(error) => this.onParseError(error, context)
);
}
private processError(context:EventPluginContext, exception:Error, stackFrames: StackTrace.StackFrame[]): Promise<any> {
var error:IError = {
message: exception.message,
stack_trace: this.getStackFrames(context, stackFrames || [])
};
context.event.data['@error'] = error;
return Promise.resolve();
}
private onParseError(error:Error, context:EventPluginContext): Promise<any> {
context.cancel = true;
var message = 'Unable to parse the exceptions stack trace';
context.log.error(`${message}: ${error.message}`);
return Promise.reject(new Error(`${message}. This exception will be discarded.`))
}
private getStackFrames(context:EventPluginContext, stackFrames:StackTrace.StackFrame[]): IStackFrame[] {
var frames:IStackFrame[] = [];
for (var index = 0; index < stackFrames.length; index++) {
frames.push({
name: stackFrames[index].functionName,
parameters: stackFrames[index].args, // TODO: need to verify arguments.
file_name: stackFrames[index].fileName,
line_number: stackFrames[index].lineNumber,
column: stackFrames[index].columnNumber
});
}
return frames;
}
}