added global script/ajax error handling.

pull/6/head
kay.one 12 years ago
parent 4cca5d21b1
commit b393c11b27

@ -194,7 +194,7 @@
<Content Include="_backboneApp\AddSeries\SearchResultModel.js" />
<Content Include="_backboneApp\AddSeries\SearchResultCollection.js" />
<Content Include="_backboneApp\Content\Intelisense\bootstrap.css" />
<Content Include="_backboneApp\errorHandler.js" />
<Content Include="_backboneApp\nzbdrone.logging.js" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.extend.js" />
<Compile Include="_backboneApp\CassetteConfiguration.cs" />
<Compile Include="Controllers\ImageController.cs" />
@ -385,6 +385,9 @@
<Content Include="_backboneApp\JsLibraries\backbone.js" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.js" />
<Content Include="_backboneApp\AddSeries\addSeriesLayoutTemplate.html" />
<Content Include="_backboneApp\Shared\ErrorModel.js" />
<Content Include="_backboneApp\Shared\ErrorTemplate.html" />
<Content Include="_backboneApp\Shared\ErrorView.js" />
<Content Include="_backboneApp\Shared\SpinnerTemplate.html" />
<Content Include="_backboneApp\Shared\SpinnerView.js" />
<None Include="_backboneApp\JsLibraries\jquery-1.8.2.intellisense.js" />

@ -50,6 +50,8 @@
</div>
<div id="content" class="row">
<div class="span20">
<div id="error-region" class="row">
</div>
<div id="sub-menu-region" class="row">
</div>
<div class="row">

@ -31,6 +31,7 @@ namespace NzbDrone.Web.Backbone.NzbDrone
bundles.Add<ScriptBundle>(NZBDRONE, new[]{
APP_PATH + "\\AddSeries\\AddSeriesLayout.js",
APP_PATH + "\\Shared\\ErrorView.js",
});

@ -58,3 +58,12 @@ body {
text-align: center;
padding: 30px;
}
#error-region .alert {
margin: 10px;
}
#error-region .alert .icon-warning-sign {
padding-right: 10px;
}

@ -0,0 +1,16 @@
/// <reference path="../app.js" />
NzbDrone.Shared.ErrorCollection = Backbone.Collection.extend({
model: NzbDrone.Shared.ErrorModel,
});
NzbDrone.Shared.ErrorModel = Backbone.Model.extend({
defaults: {
"title": "NO_TITLE",
"message": "NO_MESSAGE",
}
});

@ -0,0 +1,4 @@
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="icon-warning-sign" /><strong>{{title}}</strong> {{message}}
</div>

@ -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;
});

@ -10,7 +10,7 @@
/// <reference path="JsLibraries/backbone.marionette.extend.js" />
/// <reference path="JsLibraries/backbone.modelbinder.js" />
/// <reference path="JsLibraries/bootstrap.js" />
/// <reference path="errorHandler.js" />
/// <reference path="nzbdrone.logging.js" />
if (typeof console == "undefined") {
window.console = { log: function () { } };
@ -74,6 +74,7 @@ NzbDrone.addInitializer(function (options) {
NzbDrone.addRegions({
mainRegion: "#main-region",
errorRegion: "#error-region",
});
NzbDrone.Router = new NzbDrone.Router();

@ -1,15 +0,0 @@
/// <reference path="JsLibraries/jquery.js" />
window.onerror = function (msg, url, line) {
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).ajaxSuccess(function (event, XMLHttpRequest, ajaxOptionsa) {
console.log(ajaxOptionsa);
});

@ -0,0 +1,3 @@
$(document).ajaxSuccess(function (event, XMLHttpRequest, ajaxOptionsa) {
console.log(ajaxOptionsa);
});
Loading…
Cancel
Save