12345678910111213141516171819202122232425262728293031323334 |
- // @flow
-
- /**
- * Class used to get json data from the web
- */
- export default class WebDataManager {
-
- FETCH_URL: string;
- lastDataFetched: Object = {};
-
-
- constructor(url: string) {
- this.FETCH_URL = url;
- }
-
- /**
- * Read data from FETCH_URL and return it.
- * If no data was found, returns an empty object
- *
- * @return {Promise<Object>}
- */
- async readData() {
- let fetchedData: Object = {};
- try {
- let response = await fetch(this.FETCH_URL);
- fetchedData = await response.json();
- } catch (error) {
- throw new Error('Could not read FetchedData from server');
- }
- this.lastDataFetched = fetchedData;
- return fetchedData;
- }
-
- }
|