/* 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) { //Check if this is the same message again as last time to avoid //repetitive loops of useless messages var newHash = window.$gz.util.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("??")) { msg = msg.replace("??", ""); } window.$gz.store.commit("logItem", msg); if (devModeShowErrors) { var errMsg = "DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" + msg; // eslint-disable-next-line no-console console.log(errMsg); window.$gz.eventBus.$emit("notify-error", "Dev error see log / console"); } //If a form instance was provided (vue instance) //then put the error into it if (vm) { if (window.$gz.errorHandler.devMode()) { //make sure formState.appError is defined on data if (!window.$gz._.has(vm, "formState.appError")) { throw "DEV ERROR errorHandler::dealWithError -> formState.appError seems to be missing from form's vue data object"; } } vm.formState.appError = msg; window.$gz.form.setErrorBoxErrors(vm); } } export default { developmentModeShowErrorsImmediately(showErrorsImmediately) { devModeShowErrors = showErrorsImmediately; }, devMode() { return devModeShowErrors; }, handleGeneralError(message, source, lineno, colno, error) { var msg = "General error: \n" + message; if (source) { msg += "\nsource: " + source; } if (lineno) { msg += "\nlineno: " + lineno; } if (colno) { msg += "\ncolno: " + colno; } if (error) { msg += "\nerror: " + error; } dealWithError(msg); }, handleVueError(err, vm, info) { var msg = "Vue error: \n" + err; if (err.fileName) { msg += "\nfilename: " + err.fileName; } if (err.lineNumber) { msg += "\nlineNumber: " + err.lineNumber; } if (info) { msg += "\ninfo: " + info; } if (err.stack) { msg += "\nSTACK:\n " + err.stack; } dealWithError(msg); }, handleVueWarning(wmsg, vm, trace) { var msg = "Vue warning: \n" + wmsg; // if (vm) { // msg += "\nvm present "; // } if (trace) { msg += "\ntrace: " + trace; } dealWithError(msg); }, ///////////////////////////////////////////////// // Localize, log and return error // handleFormError(err, vm) { //called inside forms when things go wrong //returns the localized message in case the form wants to display it as well if (err instanceof Error && err.message) { dealWithError(err.message, vm); } else { dealWithError(err.toString(), vm); } } };