forked from vergnet/application-amicale
Use promise instead of await
This commit is contained in:
parent
aff897c8ce
commit
14856616df
1 changed files with 10 additions and 8 deletions
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue