Code to improve error message display (prevent repeats, log to console dev errors instead of alert box)
This commit is contained in:
@@ -1,14 +1,24 @@
|
|||||||
/* xeslint-disable */
|
/* xeslint-disable */
|
||||||
|
|
||||||
var devModeShowErrors = false;
|
var devModeShowErrors = false;
|
||||||
|
var lastMessageHash = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Localize, Log and optionally display errors
|
// Localize, Log and optionally display errors
|
||||||
// return localized message in case caller needs it
|
// return localized message in case caller needs it
|
||||||
function dealWithError(msg, vm) {
|
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);
|
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
|
//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
|
//so it's not as weird looking to the user
|
||||||
if (!devModeShowErrors && msg.includes("??")) {
|
if (!devModeShowErrors && msg.includes("??")) {
|
||||||
@@ -21,7 +31,6 @@ function dealWithError(msg, vm) {
|
|||||||
msg;
|
msg;
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(errMsg);
|
console.log(errMsg);
|
||||||
|
|
||||||
window.$gz.eventBus.$emit("notify-error", "Dev error see log / console");
|
window.$gz.eventBus.$emit("notify-error", "Dev error see log / console");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,23 @@ export default {
|
|||||||
// //No longer than 255 characters
|
// //No longer than 255 characters
|
||||||
// inObj = StringUtil.MaxLength(inObj, 255);
|
// inObj = StringUtil.MaxLength(inObj, 255);
|
||||||
// return inObj;
|
// 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
|
//new functions above here
|
||||||
|
|||||||
Reference in New Issue
Block a user