UNPKG

@northscaler/service-support

Version:

Artifacts that assist in writing service layers effectively

93 lines (67 loc) 2.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: formatters/error-formatter.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: formatters/error-formatter.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>'use strict' /** * @typedef {object} FormattedError * @property {string} [name] * @property {string} [message] * @property {string} [code] * @property {*} [info] * @property {string} [stack] * @property {object} [cause] */ /** * Formats the given error as a plain object. * * @param {object} [arg0] The argument to be deconstructed. * @param {object} [error] The `Error` (or `Error`-like object) to be formatted. * @param {boolean} [includeStack=true] Whether to include the `stack` property. * @param {boolean} [includeCause=true] Whether to include the `cause` property. * @return {FormattedError} The formatted error as a literal object. */ function formatError ({ error, includeStack = true, includeCause = true } = {}) { if (!error) return error const e = { name: error.name } if (error.message) e.message = error.message.toString() if (error.code) e.code = error.code.toString() if (error.info) e.info = error.info if (includeStack &amp;&amp; error.stack) e.stack = error.stack.toString() if (includeCause &amp;&amp; error.cause) e.cause = formatError({ error: error.cause, includeStack, includeCause }) return e } module.exports = formatError </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#DateFormat">DateFormat</a></li><li><a href="global.html#ResponseStatus">ResponseStatus</a></li><li><a href="global.html#extractDtoFromEntity">extractDtoFromEntity</a></li><li><a href="global.html#formatDate">formatDate</a></li><li><a href="global.html#formatEnumeration">formatEnumeration</a></li><li><a href="global.html#formatError">formatError</a></li><li><a href="global.html#serviceMethod">serviceMethod</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sun Oct 01 2023 23:45:36 GMT+0000 (Coordinated Universal Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>