Code to improve error message display (prevent repeats, log to console dev errors instead of alert box)

This commit is contained in:
2019-11-13 23:09:34 +00:00
parent 1d3d00c6f5
commit 7148291c20
2 changed files with 28 additions and 2 deletions

View File

@@ -1,14 +1,24 @@
/* xeslint-disable */
var devModeShowErrors = false;
var lastMessageHash = 0;
////////////////////////////////////////////////////////
//
// Localize, Log and optionally display errors
// return localized message in case caller needs it
function dealWithError(msg, vm) {
//debugger;
//Check if this is the same message again as last time to avoid
//repetitive loops of useless messages
var newHash = window.$gz.gzutil.quickHash(msg);
if (newHash == lastMessageHash) {
return;
}
lastMessageHash = newHash;
//localize as necessary
msg = window.$gz.locale.translateString(msg);
//In some cases the error may not be localizable, if this is not a debug run then it should show without the ?? that localizing puts in keys not found
//so it's not as weird looking to the user
if (!devModeShowErrors && msg.includes("??")) {
@@ -21,7 +31,6 @@ function dealWithError(msg, vm) {
msg;
// eslint-disable-next-line no-console
console.log(errMsg);
window.$gz.eventBus.$emit("notify-error", "Dev error see log / console");
}

View File

@@ -94,6 +94,23 @@ export default {
// //No longer than 255 characters
// inObj = StringUtil.MaxLength(inObj, 255);
// return inObj;
},
///////////////////////////////
// Quick hash for trivial purposes
// not cryptographic
// https://stackoverflow.com/a/7616484/8939
//
quickHash: function(theString) {
var hash = 0,
i,
chr;
if (theString.length === 0) return hash;
for (i = 0; i < theString.length; i++) {
chr = theString.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
//new functions above here