Use promise instead of await

This commit is contained in:
Arnaud Vergnet 2020-03-30 15:43:22 +02:00
parent aff897c8ce
commit 14856616df

View file

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