Skip to content

Commit

Permalink
adding basic asynchrounous code here
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalarya873 committed Aug 14, 2024
1 parent 2dc24d0 commit b089ce6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions backend/3.lecture/src/utils/ApiError.js
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;
}
}
20 changes: 18 additions & 2 deletions backend/3.lecture/src/utils/asyncHandler.js
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}

0 comments on commit b089ce6

Please sign in to comment.