application-amicale/utils/WebData.js

20 lines
481 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) {
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;
}