application-amicale/utils/WebData.js

22 lines
505 B
JavaScript
Raw Normal View History

2020-03-30 15:28:08 +02:00
// @flow
/**
* Read data from FETCH_URL and return it.
* If no data was found, returns an empty object
*
* @param url The urls to fetch data from
* @return {Promise<Object>}
*/
export async function readData(url: string) {
2020-03-30 15:43:22 +02:00
return new Promise((resolve, reject) => {
fetch(url)
.then(async (response) => response.json())
.then((data) => {
resolve(data);
})
.catch(() => {
reject();
});
});
2020-03-30 15:28:08 +02:00
}