@magic.batua/error
Version:
The Error module powers the error handling features of the Magic Batua.
116 lines (95 loc) • 4.08 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>index.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">index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
/**
* @module @magic.batua/error
* @overview Defines the `Error` handling interfaces used throughout the Magic Batua
* codebase.
*
* @author Animesh Mishra <hello@animesh.ltd>
* @copyright © 2018 Animesh Ltd. All Rights Reserved.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const Code_1 = require("./Source/Code");
exports.Code = Code_1.Code;
const ClientError_1 = require("./Source/ClientError");
exports.ClientError = ClientError_1.ClientError;
const ExternalError_1 = require("./Source/ExternalError");
exports.ExternalError = ExternalError_1.ExternalError;
/**
* @exports Error
*/
exports.description = "Exports error handling functionalities";
/**
* All the errors thrown by the application code, in any of the modules,
* are routed through this method.
*
* Upon receiving an `error`, the method first runs an identity check.
*
* - If the `error` is of type `ClientError`, it sends an error response with
* one of the 4xx status codes.
* - If the `error` is of type `ExternalError`, it sends an error response with
* a `424 Failed Dependency` status code.
* - If the `error` is of any other type, it's assumed to an internal server
* error and a `500 Internal Server Error` response is sent.
*
*
* Regardless of the error type, each response includes a detailed description,
* help message and debugging information in the response body.
*
* @param { Error } error The error thrown
* @param { Express.Response } response The response object that will be used to
* communicate the error back to the client
*/
function Handle(error, response) {
switch (error.constructor) {
case ClientError_1.ClientError:
let clientError = error;
response.status(clientError.code).json(clientError.Export());
break;
case ExternalError_1.ExternalError:
let externalError = error;
response.status(externalError.code).json(externalError.Export());
break;
default:
response.status(Code_1.Code.Internal).send(error.message);
}
}
exports.Handle = Handle;
//# sourceMappingURL=index.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>