Skip to content

Commit 4fc48fc

Browse files
authored
Update byeTryCatchErrorHandling.js
1 parent 88b4884 commit 4fc48fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Asynchronous-JavaScript/byeTryCatchErrorHandling.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,23 @@ exports.createOne = Model =>
4444
},
4545
});
4646
});
47+
48+
// another
49+
50+
const awaitHandlerFactory = (middleware) => {
51+
return async (req, res, next) => {
52+
try {
53+
await middleware(req, res, next);
54+
} catch (err) {
55+
next(err);
56+
}
57+
};
58+
};
59+
// and use it this way:
60+
app.get(
61+
"/",
62+
awaitHandlerFactory(async (request, response) => {
63+
const result = await getContent();
64+
response.send(result);
65+
})
66+
);

0 commit comments

Comments
 (0)