Ensured default servers is validated as JSON and ignored otherwise

This commit is contained in:
Alejandro Celaya
2019-10-21 19:26:09 +02:00
parent 66124370a6
commit f74d135922
2 changed files with 46 additions and 18 deletions

View File

@@ -31,9 +31,10 @@ export const listServers = ({ listServers, createServers }, { get }) => () => as
}
// If local list is empty, try to fetch it remotely and calculate IDs for every server
// It's important to parse the content to json, so that it is ignored for other formats (because it will catch)
const getDataAsJsonWithIds = pipe(prop('data'), JSON.parse, map(assocId));
const remoteList = await get(`${homepage}/servers.json`)
.then(prop('data'))
.then(map(assocId))
.then(getDataAsJsonWithIds)
.catch(() => []);
createServers(remoteList);