diff --git a/app/services/ajax-error.js b/app/services/ajax-error.js new file mode 100644 index 0000000..6cfd29a --- /dev/null +++ b/app/services/ajax-error.js @@ -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}`); + }); + } +}); diff --git a/app/utils/ajax-error-new.js b/app/utils/ajax-error-new.js deleted file mode 100644 index 37031f2..0000000 --- a/app/utils/ajax-error-new.js +++ /dev/null @@ -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}`); - }); -}