def: this is a repo with utils backend tools, like validators, errors-handlers, etc... motivated for a lazy spirit to rebuild code
- express-validator
- check validators/route-validatior
import { authValidations, authValidationsTypes } from '../validations/auth-validation';
const router = express.Router();
type SignUpRequest = {
email: string;
password: string;
};
router.post(
'/api/users/signup',
authValidations(authValidationsTypes.VALIDATE_SIGNUP),
(req, res) => {
...
}
);
- express-async-errors
- check errors/custom-error.ts
in index.ts
import express from 'express';
import 'express-async-errors';
import { errorHandler } from './middlewares/error-handler';
import { NotFoundError } from './errors/not-found-error';
.
.
.
// after the app routes
app.all('*', async () => {
throw new NotFoundError();
});
app.use(errorHandler);