From 689ea55bedb6f919a69ca96f8a7f4b146f92b2de Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 2 Dec 2015 10:13:06 -0700 Subject: [PATCH] Ajax Error Service --- app/services/ajax-error.js | 19 +++++++++++++++++++ app/utils/ajax-error-new.js | 7 ------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/services/ajax-error.js delete mode 100644 app/utils/ajax-error-new.js 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}`); - }); -}