This commit is contained in:
@@ -3,6 +3,7 @@ import store from "../store";
|
|||||||
import router from "../router";
|
import router from "../router";
|
||||||
import auth from "./auth";
|
import auth from "./auth";
|
||||||
import errorHandler from "./errorhandler";
|
import errorHandler from "./errorhandler";
|
||||||
|
import locale from "./locale";
|
||||||
|
|
||||||
function stringifyPrimitive(v) {
|
function stringifyPrimitive(v) {
|
||||||
switch (typeof v) {
|
switch (typeof v) {
|
||||||
@@ -45,11 +46,13 @@ function handleError(action, error, route, reject) {
|
|||||||
"API error: " + action + " route =" + route + ", message =" + error.message;
|
"API error: " + action + " route =" + route + ", message =" + error.message;
|
||||||
store.commit("logItem", errorMessage);
|
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");
|
store.commit("logItem", "User is not authorized, redirecting to login");
|
||||||
auth.logout();
|
auth.logout();
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
return reject("Authorization required");
|
return reject("[ErrorUserNotAuthenticated]");
|
||||||
}
|
}
|
||||||
//is it a network error?
|
//is it a network error?
|
||||||
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
|
//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")
|
error.message.includes("Network request failed")
|
||||||
) {
|
) {
|
||||||
store.commit("logItem", "Network error");
|
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";
|
//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);
|
devShowUnknownError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +77,7 @@ export default {
|
|||||||
//Handle expected api errors
|
//Handle expected api errors
|
||||||
if (response.status == 401) {
|
if (response.status == 401) {
|
||||||
//must reject if not authorized
|
//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) {
|
if (response.status >= 200 && response.status < 300) {
|
||||||
@@ -240,11 +244,6 @@ export default {
|
|||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
//fundamental error, can't proceed with this call
|
//fundamental error, can't proceed with this call
|
||||||
handleError("GET", error, route, reject);
|
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) {
|
.catch(function(error) {
|
||||||
handleError("UPSERT", error, route, reject);
|
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);
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ export default {
|
|||||||
"ErrorAPI2206",
|
"ErrorAPI2206",
|
||||||
"ErrorAPI2207",
|
"ErrorAPI2207",
|
||||||
"ErrorAPI2208",
|
"ErrorAPI2208",
|
||||||
"ErrorAPI2209"
|
"ErrorAPI2209",
|
||||||
|
"ErrorServerUnresponsive"
|
||||||
],
|
],
|
||||||
decimalValidate(required) {
|
decimalValidate(required) {
|
||||||
return { required: required, decimal: [2, this.formats.decimalSeparator] };
|
return { required: required, decimal: [2, this.formats.decimalSeparator] };
|
||||||
|
|||||||
Reference in New Issue
Block a user