From bdad866ac603bcc9704f955f21a2f2d855842f95 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 18 Apr 2013 23:38:26 -0700 Subject: [PATCH] properly detect connection issues and show appropriate message. --- Gruntfile.js | 1 + UI/Shared/NotificationCollection.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index e5f8b6ab2..a401750ac 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -124,6 +124,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-curl'); // Default task(s). grunt.registerTask('default', ['copy','less:bootstrap','handlebars', 'watch']); + grunt.registerTask('package', ['copy','less:bootstrap','handlebars']); grunt.registerTask('update', ['curl']); }; \ No newline at end of file diff --git a/UI/Shared/NotificationCollection.js b/UI/Shared/NotificationCollection.js index 186da5cfa..5dcbfff9b 100644 --- a/UI/Shared/NotificationCollection.js +++ b/UI/Shared/NotificationCollection.js @@ -1,4 +1,5 @@ -define(['app', 'Shared/NotificationModel'], function () { +"use strict"; +define(['app', 'Shared/NotificationModel'], function () { var collection = Backbone.Collection.extend({ @@ -31,7 +32,7 @@ console.log("An error occurred while reporting error. " + error); console.log(msg); - alert('Couldn\'t report JS error. ' + msg); + window.alert('Couldn\'t report JS error. ' + msg); } return false; //don't suppress default alerts and logs. @@ -39,6 +40,16 @@ $(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; @@ -49,10 +60,8 @@ return undefined; } - var model = new NzbDrone.Shared.NotificationModel(); model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); model.set('message', xmlHttpRequest.responseText); - model.set('level', 'error'); self.push(model); return false;