2013-05-04 02:50:22 +03:00
|
|
|
"use strict";
|
2013-05-06 00:24:33 +03:00
|
|
|
(function () {
|
2013-05-04 02:50:22 +03:00
|
|
|
|
|
|
|
/* var model = new NzbDrone.Shared.NotificationModel();
|
|
|
|
model.set('title','test notification');
|
|
|
|
model.set('message','test message');
|
|
|
|
model.set('level', 'error');
|
|
|
|
this.push(model);
|
|
|
|
*/
|
|
|
|
|
2013-05-21 03:34:02 +03:00
|
|
|
|
|
|
|
if (!window.console) {
|
|
|
|
window.console = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window.console.debug) {
|
|
|
|
window.console.debug = function () {
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-05-04 02:50:22 +03:00
|
|
|
window.alert = function (message) {
|
|
|
|
window.Messenger().post(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.onerror = function (msg, url, line) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = url;
|
|
|
|
var messageText = a.pathname.split('/').pop() + ' : ' + line + "</br>" + msg;
|
|
|
|
|
|
|
|
var message = {
|
|
|
|
message : messageText,
|
|
|
|
type : 'error',
|
2013-05-04 05:15:46 +03:00
|
|
|
hideAfter : 1000,
|
2013-05-04 02:50:22 +03:00
|
|
|
showCloseButton: true
|
|
|
|
};
|
|
|
|
|
|
|
|
window.Messenger().post(message);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.log("An error occurred while reporting error. " + error);
|
|
|
|
console.log(msg);
|
|
|
|
window.alert('Couldn\'t report JS error. ' + msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; //don't suppress default alerts and logs.
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) {
|
|
|
|
|
|
|
|
//don't report 200 error codes
|
|
|
|
if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
//don't report aborted requests
|
|
|
|
if (xmlHttpRequest.statusText === 'abort') {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
var message = {
|
|
|
|
type : 'error',
|
2013-05-04 05:15:46 +03:00
|
|
|
hideAfter : 1000,
|
2013-05-04 02:50:22 +03:00
|
|
|
showCloseButton: true
|
|
|
|
};
|
|
|
|
|
|
|
|
if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) {
|
2013-05-29 08:03:43 +03:00
|
|
|
return false;
|
|
|
|
//message.message = 'NzbDrone Server Not Reachable. make sure NzbDrone is running.';
|
2013-05-04 02:50:22 +03:00
|
|
|
} else {
|
2013-05-04 05:15:46 +03:00
|
|
|
message.message = "[{0}] {1} : {2}".format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url);
|
2013-05-04 02:50:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
window.Messenger().post(message);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2013-05-06 00:24:33 +03:00
|
|
|
})();
|
2013-05-04 02:50:22 +03:00
|
|
|
|