Send browser errors back to the server

(imported from commit 8c676017e8b3fc4f17552db15d32266099dba8f2)
This commit is contained in:
Zev Benjamin
2013-03-11 15:54:27 -04:00
parent 2c4c6ba43e
commit 1109d20149
3 changed files with 33 additions and 1 deletions

View File

@@ -5,6 +5,25 @@ var blueslip = (function () {
var exports = {};
var error_has_stack = Error().hasOwnProperty('stack');
function report_error(msg) {
var stack;
if (error_has_stack) {
stack = Error().stack;
} else {
stack = 'No stacktrace available';
}
$.ajax({
type: 'POST',
url: '/json/report_error',
dataType: 'json',
data: { message: msg, stacktrace: stack },
timeout: 10*1000
});
}
exports.log = function blueslip_log (msg) {
console.log(msg);
};
@@ -25,10 +44,15 @@ exports.error = function blueslip_error (msg) {
throw new Error(msg);
} else {
console.error(msg);
report_error(msg);
}
};
exports.fatal = function blueslip_fatal (msg) {
if (! debug_mode) {
report_error(msg);
}
throw new Error(msg);
};