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