From 8a52b8da029578058fbe8302a0a832abb2149092 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 19 Apr 2013 08:33:55 -0700 Subject: [PATCH] properly detect connection issues and show appropriate message. --- UI/Shared/NotificationCollection.js | 30 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/UI/Shared/NotificationCollection.js b/UI/Shared/NotificationCollection.js index 5dcbfff9b..f93918230 100644 --- a/UI/Shared/NotificationCollection.js +++ b/UI/Shared/NotificationCollection.js @@ -1,7 +1,7 @@ "use strict"; define(['app', 'Shared/NotificationModel'], function () { - var collection = Backbone.Collection.extend({ + var notificationCollection = Backbone.Collection.extend({ model: NzbDrone.Shared.NotificationModel, @@ -40,36 +40,34 @@ define(['app', 'Shared/NotificationModel'], function () { $(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) { - var model = new NzbDrone.Shared.NotificationModel(); - model.set('level', 'error'); - - if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) { - model.set('title', "Connection Failed"); - model.set('message', "NzbDrone Server Not Reachable. make sure NzbDrone is running."); - self.push(model); - return false; - } - //don't report 200 error codes if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) { return undefined; } - //doesn't report aborted requests + //don't report aborted requests if (xmlHttpRequest.statusText === 'abort') { return undefined; } - model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); - model.set('message', xmlHttpRequest.responseText); - self.push(model); + var model = new NzbDrone.Shared.NotificationModel(); + model.set('level', 'error'); + if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) { + model.set('title', "Connection Failed"); + model.set('message', "NzbDrone Server Not Reachable. make sure NzbDrone is running."); + } else { + model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); + model.set('message', xmlHttpRequest.responseText); + } + + self.push(model); return false; }); } }); - return new collection(); + return new notificationCollection(); });