This commit is contained in:
2020-06-22 21:57:38 +00:00
parent f2eef073f8
commit c6fffcf1c9
4 changed files with 109 additions and 157 deletions

View File

@@ -39,7 +39,7 @@ function stringifyPrimitive(v) {
// Try to handle an api error
// return true if handled or false if not
//
function handleError(action, error, route, reject) {
function handleError(action, error, route) {
let errorMessage =
"API error: " + action + " route =" + route + ", message =" + error.message;
window.$gz.store.commit("logItem", errorMessage);
@@ -56,11 +56,8 @@ function handleError(action, error, route, reject) {
window.$gz.translation.get("ErrorUserNotAuthorized")
);
router.push(window.$gz.store.state.homePage);
if (reject) {
return reject("[ErrorUserNotAuthorized]");
} else {
throw "[ErrorUserNotAuthorized]";
}
throw "[ErrorUserNotAuthorized]";
}
//Handle 401 not authenticated
@@ -75,11 +72,8 @@ function handleError(action, error, route, reject) {
);
router.push("/login");
if (reject) {
return reject("[ErrorUserNotAuthenticated]");
} else {
throw "[ErrorUserNotAuthenticated]";
}
throw "[ErrorUserNotAuthenticated]";
}
//is it a network error?
@@ -104,12 +98,7 @@ function handleError(action, error, route, reject) {
window.$gz.eventBus.$emit("notify-error", msg);
//note: using translation key in square brackets
if (reject) {
return reject(msg);
} else {
throw msg;
}
//throw "Error: unable to contact server";
throw msg;
}
}
@@ -122,13 +111,11 @@ export default {
status(response) {
//Handle expected api errors
if (response.status == 401) {
//must reject if not Authenticated
return Promise.reject(new Error("[ErrorUserNotAuthenticated]"));
throw new Error("[ErrorUserNotAuthenticated]");
}
if (response.status == 403) {
//must reject if not Authorized
return Promise.reject(new Error("[ErrorUserNotAuthorized]"));
throw new Error("[ErrorUserNotAuthorized]");
}
//404 not found is an expected status not worth logging allow to bubble up
@@ -140,9 +127,7 @@ export default {
if (response.status == 405) {
//Probably a development error
return Promise.reject(
new Error("Method Not Allowed (route issue?) " + response.url)
);
throw new Error("Method Not Allowed (route issue?) " + response.url);
}
if (response.status >= 200 && response.status < 300) {
@@ -165,12 +150,10 @@ export default {
statusEx(response) {
//Handle expected api errors
if (response.status == 401) {
//must reject if not Authenticated
throw new Error("[ErrorUserNotAuthenticated]");
}
if (response.status == 403) {
//must reject if not Authorized
throw new Error("[ErrorUserNotAuthorized]");
}
@@ -432,7 +415,7 @@ export default {
return r;
} catch (error) {
//fundamental error, can't proceed with this call
handleError("GET", error, route, reject);
handleError("GET", error, route);
}
},
@@ -534,7 +517,7 @@ export default {
r = await that.extractBodyEx(r);
return r;
} catch (error) {
handleError("POSTATTACHMENT", error, route, reject);
handleError("POSTATTACHMENT", error, route);
}
}
//---------------

View File

@@ -139,7 +139,6 @@ export default {
//
required(vm, ref) {
if (vm.formState.loading) {
// console.log("gzform:required rule - bailing due to loading", ref);
return true;
}
@@ -736,8 +735,7 @@ export default {
setFormState(newState) {
//this returns a promise so any function that needs to wait for this can utilize that
// if (newState.valid != null && newState.valid == false) {
// console.trace();
// console.log(newState);
// console.trace(newState);
// // debugger;
// }
return Vue.nextTick(function() {
@@ -758,7 +756,6 @@ export default {
}
if (newState.ready != null) {
console.log("gzform setting newstate ready to ", newState.ready);
newState.vm.formState.ready = newState.ready;
}
});