Browse Source

Use promise instead of await

Arnaud Vergnet 1 year ago
parent
commit
14856616df
1 changed files with 10 additions and 8 deletions
  1. 10
    8
      utils/WebData.js

+ 10
- 8
utils/WebData.js View File

@@ -8,12 +8,14 @@
8 8
  * @return {Promise<Object>}
9 9
  */
10 10
 export async function readData(url: string) {
11
-    let fetchedData: Object = {};
12
-    try {
13
-        let response = await fetch(url);
14
-        fetchedData = await response.json();
15
-    } catch (error) {
16
-        throw new Error('Could not read FetchedData from server');
17
-    }
18
-    return fetchedData;
11
+    return new Promise((resolve, reject) => {
12
+        fetch(url)
13
+            .then(async (response) => response.json())
14
+            .then((data) => {
15
+                resolve(data);
16
+            })
17
+            .catch(() => {
18
+                reject();
19
+            });
20
+    });
19 21
 }

Loading…
Cancel
Save