Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshshinde2012 committed Jul 7, 2021
2 parents 20577eb + 65ed00b commit 389de20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -86,6 +99,7 @@ chmod ug+x .git/hooks/*
- Additional considerations



<hr/>

# 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/)
9 changes: 8 additions & 1 deletion src/middleware/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand Down

0 comments on commit 389de20

Please sign in to comment.