diff --git a/README.md b/README.md index 19e8a7e..1eb4628 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ const app = express(); app.use('/meow', fn); -app.use(getErrorHandlerMiddleware((message) => console.error(message))); +app.use(getErrorHandlerMiddleware()); app.listen(8080, function() { console.log('server is up'); diff --git a/src/index.ts b/src/index.ts index ae4aecb..9dab5a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ import { NextFunction, ErrorRequestHandler } from 'express'; import { StatusCodes, getReasonPhrase } from 'http-status-codes'; -type LogFunction = (message: string) => void; export interface HttpError extends Error { statusCode?: StatusCodes; status?: StatusCodes; @@ -12,7 +11,7 @@ export interface ErrorResponse { stacktrace?: string; } -export const getErrorHandlerMiddleware: (log: LogFunction) => ErrorRequestHandler = (log) => { +export const getErrorHandlerMiddleware: () => ErrorRequestHandler = () => { const mapColoniesErrorExpressHandler: ErrorRequestHandler = ( err: HttpError, req, @@ -20,7 +19,6 @@ export const getErrorHandlerMiddleware: (log: LogFunction) => ErrorRequestHandle // eslint-disable-next-line @typescript-eslint/no-unused-vars next: NextFunction ): void => { - log(`${req.method} request to ${req.originalUrl} has failed with error: ${err.message}`); const errorResponse: ErrorResponse = { message: err.message, }; diff --git a/tests/middleware.spec.ts b/tests/middleware.spec.ts index 9c49d97..d367bb2 100644 --- a/tests/middleware.spec.ts +++ b/tests/middleware.spec.ts @@ -6,15 +6,13 @@ import * as supertest from 'supertest'; import { getErrorHandlerMiddleware, HttpError } from '../src/index'; describe('#getErrorHandlerMiddleware', function () { let expressApp: Application; - let logFn: jest.Mock; let errorFn: jest.Mock; beforeAll(function () { - logFn = jest.fn(); errorFn = jest.fn(); expressApp = express(); expressApp.use('/avi', errorFn); - expressApp.use(getErrorHandlerMiddleware(logFn)); + expressApp.use(getErrorHandlerMiddleware()); }); describe('production', function () { beforeAll(function () {