We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cb3c83c commit 00477c9Copy full SHA for 00477c9
1 file changed
Asynchronous-JavaScript/byeTryCatchErrorHandling.js
@@ -0,0 +1,22 @@
1
+// catchAwait.js
2
+const catchAwait = promise => (
3
+ promise
4
+ .then(data => ({ data, error: null }))
5
+ .catch(error => ({ error, data: null }))
6
+);
7
+
8
+module.exports = catchAwait;
9
10
+// working file
11
+const { getItems } = require('./api/items');
12
+const catchAwait = require('./utils/catchAwait');
13
14
+const allItems = async () => {
15
+ const { error, data } = await catchAwait(getItems());
16
+ if (!error) {
17
+ // code
18
+ }
19
+ console.error(error);
20
+}
21
22
+allItems();
0 commit comments