From ecd96e2535dc1b12aac6bd8d2ccd63ba28956d38 Mon Sep 17 00:00:00 2001 From: Santosh Shinde Date: Wed, 7 Jul 2021 22:55:25 +0530 Subject: [PATCH 1/2] update readme - Default System Health Status API --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c46fadf..e17d5244 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,19 @@ Try it!! I am happy to hear your feedback or any kind of new features. | **build/** | Compiled source files will be placed here | +## Default System Health Status API + +- `${host}/api/system` - Return the system information in response +- `${host}/api/time` - Return the current time in response +- `${host}/api/usage` - Return the process and system memory usage in response +- `${host}/api/process` - Return the process details in response +- `${host}/api/error` - Return the error generated object in response + +## Refrences + +- [Skeleton for Node.js Apps written in TypeScript](https://javascript.plainenglish.io/skeleton-for-node-js-apps-written-in-typescript-444fa1695b30) +- [Setup Eslint Prettier and Husky in Node JS Typescript Project](https://gist.github.com/santoshshinde2012/e1433327e5f7a58f98fe3e6651c4d5de) + ## Notes ### 1. Why is my git pre-commit hook not executable by default? @@ -86,6 +99,7 @@ chmod ug+x .git/hooks/* - Additional considerations +
-# Please connect with me on Twitter [@shindesan2012](https://twitter.com/shindesan2012) +# Please connect with me on Twitter [@shindesan2012](https://twitter.com/shindesan2012) & [https://blog.santoshshinde.com](https://blog.santoshshinde.com/) From b43177ba1009fee33095da4a42ecb705fe273089 Mon Sep 17 00:00:00 2001 From: Santosh Shinde Date: Wed, 7 Jul 2021 23:16:52 +0530 Subject: [PATCH 2/2] Fixed the error handler --- src/middleware/error-handler.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/middleware/error-handler.ts b/src/middleware/error-handler.ts index 2e62e04d..2bdcb554 100644 --- a/src/middleware/error-handler.ts +++ b/src/middleware/error-handler.ts @@ -2,12 +2,14 @@ import * as express from 'express'; import * as util from 'util'; import logger from '../lib/logger'; import ApiError from '../abstractions/ApiError'; +import { Environments } from '../environments/environment.constant'; const addErrorHandler = ( err: ApiError, req: express.Request, res: express.Response, next: express.NextFunction, ): void => { + if (err) { const status: number = err.status || 500; logger.debug(`REQUEST HANDLING ERROR: @@ -23,7 +25,12 @@ const addErrorHandler = ( status, stack: '', }; - body.stack = err.stack; + + // If the environment is production then no need to send error stack trace + if(process.env.NODE_ENV === Environments.PRODUCTION) { + body.stack = err.stack; + } + res.status(status).json(body); } next();