Spaces:
Sleeping
Sleeping
Download Backend_node/src/utils/asyncHandler.ts from VashuTheGreat2/ML-Learner: direct link, hf CLI and curl.
- Browser
- Download file 583 Bytes
-
https://huggingface.co/spaces/VashuTheGreat2/ML-Learner/resolve/main/Backend_node/src/utils/asyncHandler.ts
- Command line
-
hf download hf://spaces/VashuTheGreat2/ML-Learner/Backend_node/src/utils/asyncHandler.ts
-
curl -L -o asyncHandler.ts https://huggingface.co/spaces/VashuTheGreat2/ML-Learner/resolve/main/Backend_node/src/utils/asyncHandler.ts
583 Bytes
| import { Request, Response, NextFunction } from "express"; | |
| import logger from "../logger/create.logger.js"; | |
| type AsyncFunction = (req: Request, res: Response, next: NextFunction) => Promise<any>; | |
| const asyncHandler = (fn: AsyncFunction) => (req: Request, res: Response, next: NextFunction) => { | |
| Promise.resolve(fn(req, res, next)).catch((error: any) => { | |
| logger.error(error); | |
| res.status(error.statusCode || 500).json({ | |
| success: false, | |
| message: error.message || "Something went wrong" | |
| }); | |
| }); | |
| }; | |
| export default asyncHandler; |