diff --git a/ayanova/src/api/errorhandler.js b/ayanova/src/api/errorhandler.js index 41e6814a..6832f8dd 100644 --- a/ayanova/src/api/errorhandler.js +++ b/ayanova/src/api/errorhandler.js @@ -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"); } diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index dbfd8dba..e9dc82d9 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -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