UNPKG

@magic.batua/error

Version:

The Error module powers the error handling features of the Magic Batua.

111 lines (90 loc) 3.76 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Source/ClientError.js - Postman Documentation</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/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ClientError.html">ClientError</a><ul class='methods'><li data-type='method'><a href="ClientError.html#Export">Export</a></li></ul></li><li><a href="ExternalError.html">ExternalError</a><ul class='methods'><li data-type='method'><a href="ExternalError.html#Export">Export</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-Code.html">Code</a></li><li><a href="module-Error.html">Error</a><ul class='methods'><li data-type='method'><a href="module-Error.html#~Handle">Handle</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">Source/ClientError.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; /** * @module ClientError * @overview Defines the `ClientError` class. * * @author Animesh Mishra &lt;hello@animesh.ltd> * @copyright © 2018 Animesh Ltd. All Rights Reserved. */ Object.defineProperty(exports, "__esModule", { value: true }); /** * The `ClientError` class represents errors whose origin lie client-side. Incorrectly formatted * requests, wrong methods used for API calls and invalid tokens are some examples of a `ClientError`. * An appropriate error information and status code is shared with the client when a `ClientError` * is thrown. */ class ClientError extends Error { /** * Initialises a `ClientError` with the given HTTP status code, the error message and * an optional debugging help text. * * @param { Code } code HTTP status code for the error response * @param { string } message The error message * @param { string } help Optional debugging help text * * @constructor */ constructor(code, message, help) { super(); this.code = code; this.message = message; this.help = help; } /** * Sanitises a `ClientError` object by getting rid of the `code` property. Sending the * `code` property client-side could make the impression that client shouldn't pay * attention to the HTTP response's `status` header and should code against the response * body's `code` property instead. That would be a bad design choice. * * @returns { any } A `ClientError` object without the `code`. * * @function Export * @memberof ClientError * @instance */ Export() { let publicView = JSON.parse(JSON.stringify(this)); delete publicView.code; return publicView; } } exports.ClientError = ClientError; //# sourceMappingURL=ClientError.js.map</code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated at Mon Mar 19 2018 23:41:29 GMT+0530 (IST) </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>