1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

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
This commit is contained in:
Hannah Wolfe 2014-07-28 22:41:45 +01:00
parent 716fea4c77
commit fbba4d309c
4 changed files with 16 additions and 1 deletions

View file

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

View file

@ -0,0 +1,7 @@
{{#if importErrors}}
<table class="table">
{{#each importErrors}}
<tr><td>{{message}}</td></tr>
{{/each}}
</table>
{{/if}}

View file

@ -28,6 +28,7 @@
<fieldset>
<div class="form-group">
<label>Import</label>
{{partial "import-errors"}}
{{gh-file-upload id="importfile" uploadButtonText=uploadButtonText}}
<p>Import from another Ghost installation. If you import a user, this will replace the current user & log you out.</p>
</div>

View file

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