This commit is contained in:
2020-09-16 17:04:37 +00:00
parent 7b18f4e270
commit 3dc5f8134c
4 changed files with 73 additions and 52 deletions

View File

@@ -2,9 +2,8 @@
@@@@@@@@@@@@@@@ ROADMAP STAGE 4 - REPORTING / DASHBOARD / KPI @@@@@@@@@@@@@@@ ROADMAP STAGE 4 - REPORTING / DASHBOARD / KPI
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
todo: exception handling around reports sucks
todo: can it just scan for locale keys and prefetch them rather than user having to add up front?
todo: a script error when just running a report from the report selector acts weird todo: a script error when just running a report from the report selector acts weird
Test with dev mode off to confirm it won't show it in the UI Test with dev mode off to confirm it won't show it in the UI
Should show the error in the UI Should show the error in the UI
@@ -64,6 +63,8 @@ todo: consider feature to set server to always use a pre-set browser locale sett
YAGNI / TTM? YAGNI / TTM?
todo: make our logo smaller or move it when a biz logo is displaying on the login form
todo: hide swagger logo and branding in api explorer todo: hide swagger logo and branding in api explorer
todo: chunk-vendors has fa-brands in it which is fucking huge, what else is in there I don't need? todo: chunk-vendors has fa-brands in it which is fucking huge, what else is in there I don't need?

View File

@@ -56,6 +56,60 @@ function dealWithError(msg, vm) {
//why two error properties? //why two error properties?
window.$gz.form.setErrorBoxErrors(vm); window.$gz.form.setErrorBoxErrors(vm);
} }
///////////////////////////////////////////////////////////////////////////////////
// DECODE ERROR TO TEXT
// accept an unknown type of error variable
// and return human readable text
//
function decodeError(e, vm) {
//empty?
if (e == null || e == "") {
return "errorHandler::decodeError - Error is unknown / empty";
}
//an Error object?
if (e instanceof Error) {
return `Error - Name:${e.name}, Message:${e.message}`;
}
//API error object?
if (e.error) {
let err = e.error;
// {
// "code": "2002",
// "message": "See server log for details",
// "target": "Server internal error"
// }
let msg = "";
if (err.code) {
msg += err.code;
msg += " - ";
if (vm) {
msg += vm.$ay.t("ErrorAPI" + err.code);
}
msg += "\n";
}
if (err.target) {
msg += err.target;
msg += "\n";
}
if (err.message) {
msg += err.message;
msg += "\n";
}
return msg;
}
//Javascript Fetch API Response object?
if (e instanceof Response) {
return `http error: ${err.statusText} - ${err.status} Url: ${err.url}`;
}
//last resort
return JSON.stringify(e);
}
export default { export default {
handleGeneralError(message, source, lineno, colno, error) { handleGeneralError(message, source, lineno, colno, error) {
let msg = "General error: \n" + message; let msg = "General error: \n" + message;
@@ -77,7 +131,7 @@ export default {
dealWithError(msg); dealWithError(msg);
}, },
handleVueError(err, vm, info) { handleVueError(err, vm, info) {
let msg = "Vue error: \n" + err; let msg = "Vue error: \n" + decodeError(err, vm);
if (err.fileName) { if (err.fileName) {
msg += "\nfilename: " + err.fileName; msg += "\nfilename: " + err.fileName;
} }
@@ -90,65 +144,21 @@ export default {
if (err.stack) { if (err.stack) {
msg += "\nSTACK:\n " + err.stack; msg += "\nSTACK:\n " + err.stack;
} }
dealWithError(msg); dealWithError(msg, vm);
}, },
handleVueWarning(wmsg, vm, trace) { handleVueWarning(wmsg, vm, trace) {
let msg = "Vue warning: \n" + wmsg; let msg = "Vue warning: \n" + decodeError(wmsg, vm);
// if (vm) {
// msg += "\nvm present ";
// }
if (trace) { if (trace) {
msg += "\ntrace: " + trace; msg += "\ntrace: " + trace;
} }
dealWithError(msg); dealWithError(msg, vm);
}, },
///////////////////////////////////////////////// /////////////////////////////////////////////////
// translate, log and return error // translate, log and return error
// //
handleFormError(err, vm) { handleFormError(err, vm) {
//called inside forms when things go unexpectedly wrong //called inside forms when things go unexpectedly wrong
//returns the translated message in case the form wants to display it as well dealWithError(decodeError(err, vm), vm);
if (err instanceof Error && err.message) {
dealWithError(err.message, vm);
} else if (err.error) {
//it's an api error return object, translate and display correctly
err = err.error;
// {
// "code": "2002",
// "message": "See server log for details",
// "target": "Server internal error"
// }
let msg = "";
if (err.code) {
msg += err.code;
msg += " - ";
msg += vm.$ay.t("ErrorAPI" + err.code);
msg += "\n";
}
if (err.target) {
msg += err.target;
msg += "\n";
}
if (err.message) {
msg += err.message;
msg += "\n";
}
dealWithError(msg, vm);
} else if (err instanceof Response) {
let msg =
"http error: " +
err.statusText +
" - " +
err.status +
" Url: " +
err.url;
dealWithError(msg, vm);
} else {
//last resort
let msg = JSON.stringify(err);
dealWithError(msg, vm);
}
} }
}; };
/* /*

View File

@@ -62,7 +62,7 @@ import chartBarHorizontalControl from "./components/chart-bar-horizontal-control
//DEVELOPMENT MODE //DEVELOPMENT MODE
//THIS SHOULD BE FALSE IN RELEASE //THIS SHOULD BE FALSE IN RELEASE
//************************************************************ //************************************************************
const DEV_MODE = true; const DEV_MODE = false;
//************************************************************ //************************************************************
//************************************************************** //**************************************************************
//************************************************************** //**************************************************************
@@ -105,6 +105,14 @@ window.$gz = {
Vue.config.errorHandler = errorHandler.handleVueError; Vue.config.errorHandler = errorHandler.handleVueError;
window.onerror = errorHandler.handleGeneralError; window.onerror = errorHandler.handleGeneralError;
//unhandled rejection handler here
window.addEventListener("unhandledrejection", function(event) {
// the event object has two special properties:
alert(event.promise); // [object Promise] - the promise that generated the error
alert(event.reason); // Error: Whoops! - the unhandled error object
});
//warnings, only occur by default in debug mode not production //warnings, only occur by default in debug mode not production
Vue.config.warnHandler = errorHandler.handleVueWarning; Vue.config.warnHandler = errorHandler.handleVueWarning;

View File

@@ -629,6 +629,8 @@ async function clickHandler(menuItem) {
m.vm.duplicate(); m.vm.duplicate();
break; break;
case "report": case "report":
// throw "blah blah blah";
// throw Error("test exception");
if (m.id != null) { if (m.id != null) {
//last report selected is in m.id //last report selected is in m.id
m.vm.$router.push({ m.vm.$router.push({