本文整理汇总了TypeScript中stacktrace-js.fromError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromError函数的具体用法?TypeScript fromError怎么用?TypeScript fromError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromError函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: error
export function error(error: Error) {
StackTrace.fromError(error).then((stack) => {
console.log(stack);
}).catch((err) => {
console.error(err);
});
let stack = ErrorStackParser.parse(error) || [];
stack = stack.map((frame) => {
return {
filename: frame.fileName,
abs_path: frame.fileName,
lineno: frame.lineNumber,
colno: frame.columnNumber,
context_line: frame.functionName
};
}).reverse();
let options = getOptions({
level: LogLevel.Error,
error: error,
exception: [
{
type: error.name,
value: error.message,
stacktrace: {
frames: stack
}
}
]
});
return postData(options);
};
示例2:
this.stackString = Observable.create(observer => {
StackTrace.fromError(error)
.then(stackframes => {
let stackString: string = stackframes
.splice(0, 20)
.map(stackFrame => {
return stackFrame.toString();
})
.join('\n');
observer.next(stackString);
observer.complete();
let logMessage = {};
logMessage['errorMessage'] = this.errorMessage,
logMessage['url'] = router.url,
logMessage['stackTrace'] = stackString
let http = this.injector.get(HttpClient);
http.post('/api/writeLog', logMessage)
.subscribe({
error: error => {
console.error('An error occurred calling api/writeLog:', error);
}
});
});
});
示例3: reportError
window.onerror = (msg, url, line, col, error) => {
if (!error) {
reportError(msg.toString(), "(stack not available)");
return true;
}
// Make a preliminary report, which will be discarded if the stack conversion succeeds.
reportPreliminaryError(msg.toString(), error.stack);
// Try to make the report using source stack.
StackTrace.fromError(error).then(stackframes => {
var stringifiedStack = stackframes
.map(sf => {
return sf.toString();
})
.join("\n");
reportError(msg.toString(), stringifiedStack);
});
return true; // suppress normal handling.
};
示例4: handleError
handleError(error) {
const loggerService = this.injector.get(LoggerService);
const location = this.injector.get(LocationStrategy);
const url = location instanceof PathLocationStrategy ? location.path() : '';
const message = error.message ? error.message : error.toString();
// get the stack trace, lets grab the last 10 stacks only
StackTrace.fromError(error).then(stackframes => {
const stackString = stackframes
.splice(0, 20)
.map(function (sf) {
return sf.toString();
}).join('\n');
loggerService.log('info', { message, url, stack: stackString });
});
// IMPORTANT: Rethrow the error otherwise it gets swallowed
throw error;
}
示例5: handleError
handleError(error) {
const loggingService = this.injector.get(LoggingService);
const location = this.injector.get(LocationStrategy);
const message = error.message ? error.message : error.toString();
const url = location instanceof PathLocationStrategy ? location.path() : '';
// get the stack trace, lets grab the last 10 stacks only
StackTrace.fromError(error).then(stackframes => {
const stackString = stackframes
.splice(0, 20)
.map(function(sf) {
return sf.toString();
}).join('\n');
// log on the server
loggingService.error({ message, url, stack: stackString });
});
throw error;
}
示例6: handleError
handleError(error) {
if (Lib.DevMode()){
throw error;
}
// const loggingService = this.injector.get(LoggingService);
// const location = this.injector.get(LocationStrategy);
// const url = location instanceof PathLocationStrategy ? location.path() : '';
var message = error.message ? error.message : error.toString();
var url = 'https://secure.digitalsignage.com/stacktrace/';
// get the stack trace, lets grab the last 10 stacks only
StackTrace.fromError(error).then(stackframes => {
const stackString = stackframes
.splice(0, 20)
.map(function (sf) {
return sf.toString();
}).join('\n');
var date = moment().format('YYYY-MM-DD h:mm:ss');
message = `error :: business :: ${window['business_id']} :: studiolite :: ${date} :: ${message}`
StackTrace.report(stackString, url, message);
});
throw error;
}