diff --git a/framework/core/ember/app/adapters/application.js b/framework/core/ember/app/adapters/application.js index 2c89fcd6d..94d9c58ff 100644 --- a/framework/core/ember/app/adapters/application.js +++ b/framework/core/ember/app/adapters/application.js @@ -1,9 +1,8 @@ +import DS from 'ember-data'; import JsonApiAdapter from 'ember-json-api/json-api-adapter'; import config from '../config/environment'; export default JsonApiAdapter.extend({ - - // Todo: make this loaded via an environment variable or something host: config.apiURL, // We can get rid of this after @@ -13,6 +12,22 @@ export default JsonApiAdapter.extend({ store.metaForType(type, payload.meta); delete payload.meta; } + }, + + ajaxError: function(jqXHR) { + var errors = this._super(jqXHR); + if (errors instanceof DS.InvalidError) { + var newErrors = {}; + for (var i in errors.errors) { + var error = errors.errors[i]; + newErrors[error.path] = error.detail; + } + errors = new DS.InvalidError(newErrors); + } else if (errors instanceof JsonApiAdapter.ServerError) { + // @todo show an alert message + console.log(errors); + } + return errors; } }); \ No newline at end of file diff --git a/framework/core/ember/app/controllers/discussion.js b/framework/core/ember/app/controllers/discussion.js index b6f4be3a6..e9430ee29 100644 --- a/framework/core/ember/app/controllers/discussion.js +++ b/framework/core/ember/app/controllers/discussion.js @@ -88,11 +88,14 @@ export default Ember.ObjectController.extend(Ember.Evented, { } }, function(reason) { - var message = AlertMessage.create({ - type: 'warning', - message: reason.errors[0].detail - }); - controller.get('controllers.application').send('alert', message); + var errors = reason.errors; + for (var i in reason.errors) { + var message = AlertMessage.create({ + type: 'warning', + message: reason.errors[i] + }); + controller.get('controllers.application').send('alert', message); + } }) .finally(function() { composer.set('content.loading', false);