-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding basic asynchrounous code here
- Loading branch information
1 parent
2dc24d0
commit b089ce6
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ApiError extends Error{ | ||
constructor(statusCode, message){ | ||
super(); | ||
this.statusCode = statusCode; | ||
this.message = message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
const asyncHandler = () =>{ | ||
/*const asyncHandler = () =>{ | ||
try{ | ||
await fn(req, res, next) | ||
} | ||
catch(error){ | ||
res.status(err.code || 500).json({ | ||
success: false, | ||
message: err.message | ||
}) | ||
} | ||
}*/ | ||
|
||
const asyncHandler = (requestHandler) =>{ | ||
(req, res, next) =>{ | ||
Promise.resolve(requestHandler(req, res, next)).catch(next) | ||
|
||
} | ||
} | ||
|
||
export {asyncHandler} | ||
|
||
export {asyncHandler} |