-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorlog.js
More file actions
25 lines (25 loc) · 842 Bytes
/
Copy patherrorlog.js
File metadata and controls
25 lines (25 loc) · 842 Bytes
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
(function(errorlog, $) {
errorlog.configure = function(options) {
errorlog.url = (options.prefix || '') + 'errorlog';
};
errorlog.log = function(error) {
$.ajax({
type: 'POST',
url: errorlog.url,
data: error,
contentType: 'text/plain'
});
};
if (!$) {
throw new Error("jQuery is not available");
}
var match = new Error().stack.match(/https?:\/\/(.+):\d+:\d+/); // see <https://stackoverflow.com/questions/2976651/javascript-how-do-i-get-the-url-of-script-being-called#comment60538797_22165218>
if (match) {
match = match[1].match(/[^/]+(.*)errorlog\.js/);
var prefix = match ? match[1] : '';
errorlog.configure({prefix: prefix});
}
window.onerror = function(message, file, line) {
errorlog.log(message + ' (' + file + ':' + line + ')');
};
})(window.errorlog || (window.errorlog = {}), window.jQuery);