This commit is contained in:
@@ -3,6 +3,8 @@ import store from "../store";
|
||||
import router from "../router";
|
||||
import auth from "./auth";
|
||||
import errorHandler from "./errorhandler";
|
||||
import gzevent from "./eventbus";
|
||||
import gzlocale from "./locale"
|
||||
|
||||
function stringifyPrimitive(v) {
|
||||
switch (typeof v) {
|
||||
@@ -30,7 +32,8 @@ function devShowUnknownError(error) {
|
||||
// eslint-disable-next-line
|
||||
console.log(error);
|
||||
// eslint-disable-next-line
|
||||
alert(
|
||||
gzevent.$emit(
|
||||
"popup-message",
|
||||
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
|
||||
);
|
||||
}
|
||||
@@ -45,14 +48,18 @@ function handleError(action, error, route, reject) {
|
||||
"API error: " + action + " route =" + route + ", message =" + error.message;
|
||||
store.commit("logItem", errorMessage);
|
||||
|
||||
//BUGBUG?? What if the 401 is just a rights issue and not because they have no authentication at all??
|
||||
//perhaps that would never happen
|
||||
//TODO HANDLE 403 not authorized
|
||||
//popup then reject then go back in navigation or home, maybe home to be safe
|
||||
//gzlocale.get("Save")
|
||||
|
||||
//Handle 401 not authenticated
|
||||
if (error.message && error.message.includes("NotAuthenticated")) {
|
||||
store.commit("logItem", "User is not authorized, redirecting to login");
|
||||
auth.logout();
|
||||
router.push("/login");
|
||||
return reject("[ErrorUserNotAuthenticated]");
|
||||
}
|
||||
|
||||
//is it a network error?
|
||||
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
|
||||
if (error instanceof TypeError) {
|
||||
@@ -84,7 +91,6 @@ export default {
|
||||
return Promise.reject(new Error("[ErrorUserNotAuthorized]"));
|
||||
}
|
||||
|
||||
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return Promise.resolve(response);
|
||||
} else {
|
||||
|
||||
@@ -184,6 +184,10 @@ export default {
|
||||
vm.$gzevent.$on("menu-click", function handleMenuClick(menuitem) {
|
||||
self.handleAppClick(vm, menuitem);
|
||||
});
|
||||
|
||||
vm.$gzevent.$on("popup-message", function handlePopupMessage(msg) {
|
||||
alert(msg);
|
||||
});
|
||||
}
|
||||
//new functions above here
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user