Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleError(error: 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() : "";
/**
* TODO: 想一下怎么做一个简单的APM
* 最好都用elk技术栈配合skywalking前后一条龙
* 1. 记录首屏加载,文档加载(DOMContentLoaded),页面加载(load),脚本错误,慢路由
* 2. 跟踪业务流程
* 3. 离线存储和在线存储
* 4. 生成Source-map,webpack打包后的代码报错你是trace不到的
* 5. 错误预警,统计报表
*/
// 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;
}
}
function resolveError(err, firstFrameIndex) {
// This will use sourcemaps and normalize the stack frames
return StackTrace.fromError(err).then(function(stack) {
var lines = [err.toString()];
// Reconstruct to a JS stackframe as expected by Error Reporting parsers.
for (var s = firstFrameIndex; s < stack.length; s++) {
// Cannot use stack[s].source as it is not populated from source maps.
lines.push([
' at ',
// If a function name is not available '' will be used.
stack[s].getFunctionName() || '', ' (',
stack[s].getFileName(), ':',
stack[s].getLineNumber(), ':',
stack[s].getColumnNumber(), ')',
].join(''));
}
return lines.join('\n');
}, function(reason) {
// Failure to extract stacktrace
const e = new Error()
if (typeof error === 'string') {
e.name = error
e.message = error
} else if (typeof error === 'number') {
e.name = error.toString()
e.message = error.toString()
} else if (error instanceof Error) {
e.name = error.name
e.message = error.message
e.stack = error.stack
} else {
e.name = 'unknown'
e.message = 'unknown'
}
StackTrace.fromError(e, { offline: true }).then(frames => {
// Crashlytics.recordCustomExceptionName(e.message, e.message, frames)
const updatedFrames = frames.map(row => ({
lineNumber: row.lineNumber,
columnNumber: row.columnNumber,
functionName: row.functionName,
fileName: `${row.fileName}:${row.lineNumber || 0}:${row.columnNumber ||
0}`
}))
Firebase.crashlytics().recordError(0, e.message)
// Crashlytics.recordCustomExceptionName(e.message, e.message, updatedFrames)
})
if (originalHandler) {
if (Platform.OS === 'ios') {
originalHandler(error, isFatal)
} else {
// On Android, throwing the original exception immediately results in the
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;
}
uncaught.addListener(err => {
// this will transform the error's `stack` property
// to be consistently similar to Gecko and V8 stackframes
StackTrace.fromError(err)
.then(stackframes => {
err.stack = prepareStackTrace(err, stackframes);
logger.error(err);
})
.catch(err_ => {
logger.error(err);
logger.error(err_);
});
});
return new Promise((resolve: any) => {
// This one has a promise too
ST.fromError(error, {offline: true}).then((frames: ST.StackFrame[]) => {
const stackStr = (frames.map((frame: ST.StackFrame) => {
return frame.toString();
}) ).join("\n ");
result += "\n" + stackStr;
// This resolves our returned promise
resolve(result);
}).catch(() => {
result = "Unexpected error object was passed in. ";
try {
result += "Could not resolve it, stringified object: " + JSON.stringify(error);
}
catch (e) {
// Cannot stringify can only tell something was wrong.
result += "Could not resolve it or stringify it.";
.catch(e => {
try {
if (db) db.close();
if (e.isNiceError) {
console.error("Problem message:")
console.error(e.message);
} else {
require("stacktrace-js").fromError(e)
.then(function(frames) {
var lineno = 0, sourcefile = "(an unknown file)";
if (frames.length) {
lineno = frames[0].lineNumber + ":" + frames[0].columnNumber;
sourcefile = path.relative(__dirname, frames[0].fileName);
}
console.error("\nAn internal error has occurred: " + e.message + ".\n" +
"Internal errors are by definition a bug in Measure, and should be reported.\n" +
"The error was detected at line " + lineno + " of '" + sourcefile + "'.\n" +
"This should never happen, and I am halting in abject failure.");
})
.catch(function(ste) {
console.error("\nAn internal error has occurred: " + e.message + ".\n" +
"Internal errors are by definition a bug in Measure, and should be reported.\n" +
"Additionally, while handling that error another error occurred: " +
ste.message + ".\n" +
recordError(error) {
if (isError(error)) {
StackTrace.fromError(error, { offline: true }).then(stackFrames => {
this.native.recordError(createNativeErrorObj(error, stackFrames, false));
});
} else {
console.warn(
'firebase.crashlytics().recordError(*) expects an instance of Error. Non Errors will be ignored.',
);
}
}
window.addEventListener('error', ({ message, filename, lineno, colno, error }) => {
StackTrace.fromError(error)
.then(stacktrace => {
socket.log('error', message, {
colno,
filename,
lineno,
stacktrace,
});
})
.catch(() => {
socket.log('error', message, {
colno,
filename,
lineno,
});
});
});
componentDidMount() {
StackTrace.fromError(this.state).then(frames => {
this.setState({
frames: frames
.map((frame, i) => ({
...frame,
functionName: this.state.frames[i].functionName,
fileName: frame.fileName.replace(window.location.origin, ""),
}))
.map(formatFrame),
});
});
}