Skip to content

Instantly share code, notes, and snippets.

@tridungle
Forked from alexpermiakov/errorHandlers.ts
Created June 14, 2019 16:23
Show Gist options
  • Save tridungle/5b1c98abdfedeb0dbb37d647d3bc079a to your computer and use it in GitHub Desktop.
Save tridungle/5b1c98abdfedeb0dbb37d647d3bc079a to your computer and use it in GitHub Desktop.
import { Request, Response, NextFunction, Router } from "express";
import * as ErrorHandler from "../utils/ErrorHandler";
const handle404Error = (router: Router) => {
router.use((req: Request, res: Response) => {
ErrorHandler.notFoundError();
});
};
const handleClientError = (router: Router) => {
router.use((err: Error, req: Request, res: Response, next: NextFunction) => {
ErrorHandler.clientError(err, res, next);
});
};
const handleServerError = (router: Router) => {
router.use((err: Error, req: Request, res: Response, next: NextFunction) => {
ErrorHandler.serverError(err, res, next);
});
};
export default [handle404Error, handleClientError, handleServerError];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment