mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-30 11:48:26 -07:00
added global script/ajax error handling.
This commit is contained in:
parent
4cca5d21b1
commit
b393c11b27
10 changed files with 109 additions and 17 deletions
68
NzbDrone.Web/_backboneApp/Shared/ErrorView.js
Normal file
68
NzbDrone.Web/_backboneApp/Shared/ErrorView.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
/// <reference path="../app.js" />
|
||||
/// <reference path="ErrorModel.js" />
|
||||
|
||||
NzbDrone.Shared.ErrorItemView = Backbone.Marionette.ItemView.extend({
|
||||
template: "Shared/ErrorTemplate",
|
||||
});
|
||||
|
||||
NzbDrone.Shared.ErrorView = Backbone.Marionette.CollectionView.extend({
|
||||
|
||||
itemView: NzbDrone.Shared.ErrorItemView,
|
||||
|
||||
initialize: function () {
|
||||
|
||||
this.collection = new NzbDrone.Shared.ErrorCollection();
|
||||
this.listenTo(this.collection, 'reset', this.render);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
NzbDrone.addInitializer(function (options) {
|
||||
|
||||
console.log("initializing error handler");
|
||||
|
||||
NzbDrone.Shared.ErrorView.instance = new NzbDrone.Shared.ErrorView();
|
||||
|
||||
NzbDrone.errorRegion.show(NzbDrone.Shared.ErrorView.instance);
|
||||
|
||||
});
|
||||
|
||||
|
||||
window.onerror = function (msg, url, line) {
|
||||
|
||||
var errorView = NzbDrone.Shared.ErrorView.instance;
|
||||
|
||||
if (errorView) {
|
||||
var model = new NzbDrone.Shared.ErrorModel();
|
||||
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
|
||||
model.set('title', a.pathname.split('/').pop() + " : " + line);
|
||||
model.set('message', msg);
|
||||
errorView.collection.add(model);
|
||||
} else {
|
||||
alert("Error: " + msg + "\nurl: " + url + "\nline #: " + line);
|
||||
}
|
||||
|
||||
var suppressErrorAlert = false;
|
||||
// If you return true, then error alerts (like in older versions of
|
||||
// Internet Explorer) will be suppressed.
|
||||
return suppressErrorAlert;
|
||||
};
|
||||
|
||||
$(document).ajaxError(function (event, XMLHttpRequest, ajaxOptionsa) {
|
||||
|
||||
var errorView = NzbDrone.Shared.ErrorView.instance;
|
||||
|
||||
var model = new NzbDrone.Shared.ErrorModel();
|
||||
model.set('title', ajaxOptionsa.url + " : " + XMLHttpRequest.statusText);
|
||||
model.set('message', XMLHttpRequest.responseText);
|
||||
errorView.collection.add(model);
|
||||
|
||||
var suppressErrorAlert = false;
|
||||
// If you return true, then error alerts (like in older versions of
|
||||
// Internet Explorer) will be suppressed.
|
||||
return suppressErrorAlert;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue