Ajax Error Service

This commit is contained in:
Matthew Dillon 2015-12-02 10:13:06 -07:00
parent 9496de21d9
commit 689ea55bed
2 changed files with 19 additions and 7 deletions

View file

@ -0,0 +1,19 @@
import Ember from 'ember';
const { Service, inject: { service } } = Ember;
export default Service.extend({
flashMessages: service(),
alert: function(error) {
const flash = this.get('flashMessages');
flash.clearMessages();
window.scrollTo(0,0);
error.errors.forEach((error) => {
console.error(error);
const source = error.source.pointer.split('/');
flash.error(`${source[source.length-1].replace(/([A-Z])/g, ' $1').capitalize()} - ${error.detail}`);
});
}
});

View file

@ -1,7 +0,0 @@
export default function ajaxErrorNew(error, flash) {
flash.clearMessages();
error.errors.forEach((error) => {
const source = error.source.pointer.split('/');
flash.error(`${source[source.length-1].replace(/([A-Z])/g, ' $1').capitalize()} - ${error.detail}`);
});
}