mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 13:51:48 +00:00
Ensured response from servers.json has been parsed to a json array
This commit is contained in:
@@ -32,9 +32,19 @@ 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 getDataAsArrayWithIds = pipe(
|
||||
prop('data'),
|
||||
(value) => {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error('Value is not an array');
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
map(assocId),
|
||||
);
|
||||
const remoteList = await get(`${homepage}/servers.json`)
|
||||
.then(getDataAsJsonWithIds)
|
||||
.then(getDataAsArrayWithIds)
|
||||
.catch(() => []);
|
||||
|
||||
createServers(remoteList);
|
||||
|
||||
Reference in New Issue
Block a user