This commit is contained in:
2019-04-08 17:09:35 +00:00
parent 3400b9de3f
commit fa360f03b3
11 changed files with 94 additions and 73 deletions

View File

@@ -1,5 +1,5 @@
/* Xeslint-disable */
import apiUtil from "./apiutil";
import apiUtil from "./gzapi";
import { processLogin, processLogout } from "./authutil";
export default {

View File

@@ -4,7 +4,7 @@ import router from "../router";
import auth from "./auth";
import errorHandler from "./errorhandler";
var stringifyPrimitive = function(v) {
function stringifyPrimitive(v) {
switch (typeof v) {
case "string":
return v;
@@ -18,20 +18,55 @@ var stringifyPrimitive = function(v) {
default:
return "";
}
};
}
var devShowUnknownError = function(error) {
/////////////////////////////////////////////////
// Show unexpected errors during development
//
function devShowUnknownError(error) {
if (errorHandler.devMode) {
// eslint-disable-next-line
console.log("apiutil::devShowUnknownError, error is:");
console.log("gzapi::devShowUnknownError, error is:");
// eslint-disable-next-line
console.log(error);
// eslint-disable-next-line
alert(
"DEV ERROR apiutil::devShowUnknownError - unexpected error during api operation see console "
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
);
}
};
}
////////////////////////////////////////////
// Try to handle an api error
// return true if handled or false if not
//
function handleError(action, error, route, reject) {
var errorMessage =
"API error: " + action + " route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage);
if (error.message && error.message.includes("401")) {
store.commit("logItem", "User is not authorized, redirecting to login");
auth.logout();
router.push("/login");
return reject("Authorization required");
}
//is it a network error?
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
if (error instanceof TypeError) {
if (
error.message.includes("Failed to fetch") ||
error.message.includes("NetworkError") ||
error.message.includes("Network request failed")
) {
store.commit("logItem", "Network error");
return reject("Error: unable to contact server");
//throw "Error: unable to contact server";
}
}
//Ideally this should never get called because any issue should be addressed above
devShowUnknownError(error);
}
export default {
status(response) {
@@ -135,7 +170,7 @@ export default {
store.commit("setHelpURL", "http://localhost:7575/docs/");
store.commit(
"logItem",
"apiutil::APIUrl -> setting to dev. mode: " + store.state.apiUrl
"gzapi::APIUrl -> setting to dev. mode: " + store.state.apiUrl
);
} else {
//production location <protocol>//<hostname>:<port>/
@@ -149,7 +184,7 @@ export default {
);
store.commit(
"logItem",
"apiutil::APIUrl -> setting to: " + store.state.apiUrl
"gzapi::APIUrl -> setting to: " + store.state.apiUrl
);
}
}
@@ -204,23 +239,12 @@ export default {
})
.catch(function(error) {
//fundamental error, can't proceed with this call
var errorMessage =
"API error: GET route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage);
if (error.message && error.message.includes("401")) {
store.commit(
"logItem",
"User is not authorized, redirecting to login"
);
auth.logout();
router.push("/login");
} else {
//This should never get called because any issue should be addressed above in a proper error handler
devShowUnknownError(error);
reject(error);
}
handleError("GET", error, route, reject);
// {
// //Ideally this should never get called because any issue should be addressed above by errorHandler
// devShowUnknownError(error);
// reject(error);
// }
});
});
},
@@ -247,24 +271,13 @@ export default {
resolve(response);
})
.catch(function(error) {
handleError("UPSERT", error, route, reject);
//fundamental error, can't proceed with this call
var errorMessage =
"API error: UPSERT route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage);
if (error.message && error.message.includes("401")) {
store.commit(
"logItem",
"User is not authorized, redirecting to login"
);
auth.logout();
router.push("/login");
} else {
//This should never get called because any issue should be addressed above in a proper error handler
devShowUnknownError(error);
reject(error);
}
// 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

@@ -335,7 +335,6 @@ export default {
// SetErrorBoxErrors
// Gather server errors and set the appropriate keys
SetErrorBoxErrors(v) {
**THIS**
//maybe just put all the code in here and don't call geterrorboxerrors at all as no one else will need to call it anyway
var errs = this.ServerErrors(v, "errorbox");
var ret = GetErrorBoxErrors(v, errs);

View File

@@ -2,7 +2,7 @@
import store from "../store";
import roles from "./roles";
import locale from "./locale";
import api from "./apiutil";
import api from "./gzapi";
function addNavItem(title, icon, route) {
store.commit("addNavItem", {

View File

@@ -1,6 +1,6 @@
/* ZZeslint-disable */
import store from "../store";
import apiUtil from "./apiutil";
import apiUtil from "./gzapi";
import _ from "../libs/lodash.min.js";
export default {