From fbba4d309c4d144ac62f19d37a76b399aeb5b680 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 28 Jul 2014 22:41:45 +0100 Subject: [PATCH] Improve importer error messaging closes #3274 - Ensure that validation errors are always handled by moving them into the importer - Ensure that db errors are handled consistently across sqlite and mysql - Change the errors to be output in a table, with a short failure notification - Add tests for 003 importing bad files --- controllers/debug.js | 7 ++++++- templates/-import-errors.hbs | 7 +++++++ templates/debug.hbs | 1 + utils/notifications.js | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 templates/-import-errors.hbs diff --git a/controllers/debug.js b/controllers/debug.js index c65511e69..4fdc18b0d 100644 --- a/controllers/debug.js +++ b/controllers/debug.js @@ -1,5 +1,6 @@ var DebugController = Ember.Controller.extend(Ember.Evented, { uploadButtonText: 'Import', + importErrors: '', actions: { onUpload: function (file) { @@ -7,6 +8,7 @@ var DebugController = Ember.Controller.extend(Ember.Evented, { formData = new FormData(); this.set('uploadButtonText', 'Importing'); + this.notifications.closePassive(); formData.append('importfile', file); @@ -20,7 +22,10 @@ var DebugController = Ember.Controller.extend(Ember.Evented, { }).then(function () { self.notifications.showSuccess('Import successful.'); }).catch(function (response) { - self.notifications.showAPIError(response); + if (response && response.jqXHR && response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) { + self.set('importErrors', response.jqXHR.responseJSON.errors); + } + self.notifications.showError('Import Failed'); }).finally(function () { self.set('uploadButtonText', 'Import'); self.trigger('reset'); diff --git a/templates/-import-errors.hbs b/templates/-import-errors.hbs new file mode 100644 index 000000000..2958b34e7 --- /dev/null +++ b/templates/-import-errors.hbs @@ -0,0 +1,7 @@ +{{#if importErrors}} + +{{#each importErrors}} + +{{/each}} +
{{message}}
+{{/if}} \ No newline at end of file diff --git a/templates/debug.hbs b/templates/debug.hbs index f18500e7f..ce7da94d9 100644 --- a/templates/debug.hbs +++ b/templates/debug.hbs @@ -28,6 +28,7 @@
+ {{partial "import-errors"}} {{gh-file-upload id="importfile" uploadButtonText=uploadButtonText}}

Import from another Ghost installation. If you import a user, this will replace the current user & log you out.

diff --git a/utils/notifications.js b/utils/notifications.js index 5e6aa4c5b..60ba2c000 100644 --- a/utils/notifications.js +++ b/utils/notifications.js @@ -52,6 +52,8 @@ var Notifications = Ember.ArrayProxy.extend({ if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.error) { this.showError(resp.jqXHR.responseJSON.error, delayed); + } else if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.errors) { + this.showErrors(resp.jqXHR.responseJSON.errors, delayed); } else { this.showError(defaultErrorText, delayed); }