Is there a way to pretty print a user event script...
# suitescript
s
Is there a way to pretty print a user event script error?
d
throw it through
JSON.stringify(…)
Copy code
try {
    // some code that throws error
} catch (e) {
    log.error({
        title: e.title,
        details: JSON.stringify(e)
    });
}
s
I was hoping to display a nice error when doing a throw error
m
Copy code
/**
   * 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>
 `;
  };
message has been deleted
I'm using this in a suitelet. It will prob be a little challenging to use this in UE though