From 83f5df92ab639281d439211b5a2f5dd20a02f0bc Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 8 Apr 2019 17:29:01 +0000 Subject: [PATCH] --- ayanova/src/api/gzapi.js | 25 +++++++++---------------- ayanova/src/api/locale.js | 3 ++- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ayanova/src/api/gzapi.js b/ayanova/src/api/gzapi.js index bf7ca024..2999909f 100644 --- a/ayanova/src/api/gzapi.js +++ b/ayanova/src/api/gzapi.js @@ -3,6 +3,7 @@ import store from "../store"; import router from "../router"; import auth from "./auth"; import errorHandler from "./errorhandler"; +import locale from "./locale"; function stringifyPrimitive(v) { switch (typeof v) { @@ -45,11 +46,13 @@ function handleError(action, error, route, reject) { "API error: " + action + " route =" + route + ", message =" + error.message; store.commit("logItem", errorMessage); - if (error.message && error.message.includes("401")) { + //BUGBUG?? What if the 401 is just a rights issue and not because they have no authentication at all?? + //perhaps that would never happen + if (error.message && error.message.includes("NotAuthenticated")) { store.commit("logItem", "User is not authorized, redirecting to login"); auth.logout(); router.push("/login"); - return reject("Authorization required"); + return reject("[ErrorUserNotAuthenticated]"); } //is it a network error? //https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435 @@ -60,11 +63,12 @@ function handleError(action, error, route, reject) { error.message.includes("Network request failed") ) { store.commit("logItem", "Network error"); - return reject("Error: unable to contact server"); + //note: using locale key in square brackets + return reject("[ErrorServerUnresponsive]"); //throw "Error: unable to contact server"; } } - //Ideally this should never get called because any issue should be addressed above + //Ideally this should never get called because any issue should be addressed above devShowUnknownError(error); } @@ -73,7 +77,7 @@ export default { //Handle expected api errors if (response.status == 401) { //must reject if not authorized - return Promise.reject(new Error("401 - NOT AUTHORIZED")); + return Promise.reject(new Error("[ErrorUserNotAuthenticated]")); } if (response.status >= 200 && response.status < 300) { @@ -240,11 +244,6 @@ export default { .catch(function(error) { //fundamental error, can't proceed with this call handleError("GET", error, route, reject); - // { - // //Ideally this should never get called because any issue should be addressed above by errorHandler - // devShowUnknownError(error); - // reject(error); - // } }); }); }, @@ -272,12 +271,6 @@ export default { }) .catch(function(error) { handleError("UPSERT", error, route, reject); - //fundamental error, can't proceed with this call - // if (!handleError("UPSERT", error, route)) { - // //This should (ideally) never get called because any issue should be addressed above by handleError - // devShowUnknownError(error); - // reject(error); - // } }); }); } diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index cabb947a..cca38ccc 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -88,7 +88,8 @@ export default { "ErrorAPI2206", "ErrorAPI2207", "ErrorAPI2208", - "ErrorAPI2209" + "ErrorAPI2209", + "ErrorServerUnresponsive" ], decimalValidate(required) { return { required: required, decimal: [2, this.formats.decimalSeparator] };