error-handler-e2
Advanced tools
Comparing version 3.1.2 to 4.0.0
@@ -749,23 +749,38 @@ (function (global, factory) { | ||
class Middleware { | ||
constructor() { | ||
this.loggerMiddleware = (req, res, next) => { | ||
const currentDateTime = new Date(); | ||
const formattedDate = `${currentDateTime.getFullYear()}-${currentDateTime.getMonth() + 1}-${currentDateTime.getDate()} ${currentDateTime.getHours()}:${currentDateTime.getMinutes()}:${currentDateTime.getSeconds()}`; | ||
const { method } = req; | ||
const { url } = req; | ||
const status = res.statusCode; | ||
const message = `[${formattedDate}] ${method}:${url} ${status}`; | ||
// LOG Message | ||
// eslint-disable-next-line no-console | ||
console.log(message); | ||
next(); | ||
}; | ||
const loggerMiddleware$1 = (req, res, next) => { | ||
const currentDateTime = new Date(); | ||
const formattedDate = `${currentDateTime.getFullYear()}-${currentDateTime.getMonth() + 1}-${currentDateTime.getDate()} ${currentDateTime.getHours()}:${currentDateTime.getMinutes()}:${currentDateTime.getSeconds()}`; | ||
const { method } = req; | ||
const { url } = req; | ||
const status = res.statusCode; | ||
const message = `[${formattedDate}] ${method}:${url} ${status}`; | ||
// LOG Message | ||
// eslint-disable-next-line no-console | ||
console.log(message); | ||
next(); | ||
}; | ||
const handleError = (err, req, res, next) => { | ||
if (err instanceof CustomError) { | ||
next(); | ||
return res.status(err.statusCode).send(err.serializeError()); | ||
} | ||
} | ||
var logger = new Middleware(); | ||
next(); | ||
return res.status(INTERNAL_SERVER_ERROR).send({ | ||
Error: 'Internal Server Error', | ||
}); | ||
}; | ||
const notFound = (req, res) => res.status(NOT_FOUND).json(Object.assign({}, new NotFound('Not Found').serializeError())); | ||
/* eslint-disable import/prefer-default-export */ | ||
const loggerMiddleware = loggerMiddleware$1; | ||
const handleErrorMiddleware = handleError; | ||
const notFoundMiddleware = notFound; | ||
var index = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
logger: logger | ||
loggerMiddleware: loggerMiddleware, | ||
handleErrorMiddleware: handleErrorMiddleware, | ||
notFoundMiddleware: notFoundMiddleware | ||
}); | ||
@@ -772,0 +787,0 @@ |
@@ -1,3 +0,4 @@ | ||
import logger from './logger'; | ||
export { logger, }; | ||
export declare const loggerMiddleware: (req: any, res: any, next: any) => void; | ||
export declare const handleErrorMiddleware: (err: any, req: any, res: any, next: any) => any; | ||
export declare const notFoundMiddleware: (req: any, res: any) => any; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,6 +0,3 @@ | ||
declare class Middleware { | ||
loggerMiddleware: (req: any, res: any, next: any) => void; | ||
} | ||
declare const _default: Middleware; | ||
export default _default; | ||
declare const loggerMiddleware: (req: any, res: any, next: any) => void; | ||
export default loggerMiddleware; | ||
//# sourceMappingURL=logger.d.ts.map |
{ | ||
"name": "error-handler-e2", | ||
"version": "3.1.2", | ||
"version": "4.0.0", | ||
"description": "This is handle error package", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
@@ -150,2 +150,4 @@ # Error Handler E2 | ||
* [loggerMiddleware](#loggerMiddleware) | ||
* [handleErrorMiddleware](#handleErrorMiddleware) | ||
* [notFoundMiddleware](#notFoundMiddleware) | ||
@@ -160,2 +162,22 @@ ### loggerMiddleware | ||
``` | ||
### handleErrorMiddleware | ||
```js | ||
const { Middleware:{ handleErrorMiddleware }} = require('error-handler-e2'); | ||
app.use(handleErrorMiddleware); | ||
``` | ||
### handleErrorMiddleware | ||
```js | ||
const { Middleware:{ notFoundMiddleware }} = require('error-handler-e2'); | ||
app.use(notFoundMiddleware); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83636
41
1396
181