screnshaw
10/28/2021, 2:17 PMDavid B
10/28/2021, 8:10 PMJSON.stringify(…)
David B
10/28/2021, 8:11 PMtry {
// some code that throws error
} catch (e) {
log.error({
title: e.title,
details: JSON.stringify(e)
});
}
screnshaw
10/28/2021, 8:27 PMmichoel
10/28/2021, 10:10 PM/**
* Create a pretty error page to replace the native NetSuite one
*
* @param {Error|string} error
* @param {string} [errorId] an optional random string used to identify the error in logs
* @returns {string} formatted error message
*/
exports.formatErrorMessage = (error, errorId) => {
if (typeof error === "string") {
error = new Error(error);
}
const stackTrace =
typeof error.stack === "object" ? error.stack : (error.stack || "").split("\n").filter((elem) => elem);
return `
<!DOCTYPE html>
<html lang="en">
<head>
<title>Error</title>
<style>
html, body, pre {
margin: 0;
padding: 0;
font-family: Monaco, 'Lucida Console', monospace;
background: #ECECEC;
}
h1 {
margin: 0;
background: #A31012;
padding: 20px 45px;
color: #fff;
text-shadow: 1px 1px 1px rgba(0,0,0,.3);
border-bottom: 1px solid #690000;
font-size: 28px;
}
.error {
margin: 0;
padding: 15px 45px;
background: #F5A0A0;
border-top: 4px solid #D36D6D;
color: #730000;
font-size: 14px;
border-bottom: 1px solid #BA7A7A;
}
pre {
padding: 10px;
}
</style>
</head>
<body>
<h1>Oops, an error occurred</h1>
<div class="error">
<h3>Error Code</h3>
<p>${error.name}</p>
<h3>Error Message</h3>
<pre>${_.escape(error.message)}</pre>
${
errorId &&
`
<h3>Error ID</h3>
<p>${errorId}</p>`
}
<h3>Stack Trace</h3>
<ul>${stackTrace.map((line) => `<li>${line}</li>`).join("\n")}</ul>
</div>
</body>
</html>
`;
};
michoel
10/28/2021, 10:12 PMmichoel
10/28/2021, 10:13 PM