From b0836b18994ec8252eeae2dd27c541390d79be05 Mon Sep 17 00:00:00 2001 From: nathans1309 Date: Thu, 9 Feb 2017 15:36:31 -0600 Subject: [PATCH] update app.js Its my understanding that a promise chain can be returned instead of creating a new promise. I'm not sure that it is better but I think it is more readable. --- public/js/app.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 11b72d6..8e47f3c 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -154,19 +154,15 @@ class Form { * @param {string} url */ submit(requestType, url) { - return new Promise((resolve, reject) => { - axios[requestType](url, this.data()) - .then(response => { - this.onSuccess(response.data); - - resolve(response.data); - }) - .catch(error => { - this.onFail(error.response.data); - - reject(error.response.data); - }); - }); + return axios[requestType](url, this.data()) + .then(response => { + this.onSuccess(response.data); + return response.data; + }) + .catch(error => { + this.onFail(error.response.data); + throw error.response.data; + }); }