Ajax Error Service
This commit is contained in:
parent
9496de21d9
commit
689ea55bed
2 changed files with 19 additions and 7 deletions
19
app/services/ajax-error.js
Normal file
19
app/services/ajax-error.js
Normal 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}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
|
@ -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}`);
|
|
||||||
});
|
|
||||||
}
|
|
Reference in a new issue