This commit is contained in:
2019-04-08 17:29:01 +00:00
parent fa360f03b3
commit 83f5df92ab
2 changed files with 11 additions and 17 deletions

View File

@@ -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);
// }
});
});
}

View File

@@ -88,7 +88,8 @@ export default {
"ErrorAPI2206",
"ErrorAPI2207",
"ErrorAPI2208",
"ErrorAPI2209"
"ErrorAPI2209",
"ErrorServerUnresponsive"
],
decimalValidate(required) {
return { required: required, decimal: [2, this.formats.decimalSeparator] };