1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fix unhandled rejection for invalid response

This commit is contained in:
Bill Thornton 2022-07-01 12:06:41 -04:00
parent 01dba76f36
commit df1f111320

View file

@ -50,30 +50,26 @@ export async function serverAddress() {
console.debug('URL candidates:', urls);
const promises = urls.map(url => {
return fetch(`${url}/System/Info/Public`).then(resp => {
return {
url: url,
response: resp
};
}).catch(() => {
return Promise.resolve();
});
return fetch(`${url}/System/Info/Public`)
.then(async resp => {
if (!resp.ok) {
return;
}
return {
url: url,
config: await resp.json()
};
}).catch(() => { /* swallow errors */ });
});
return Promise.all(promises).then(responses => {
responses = responses.filter(obj => obj && obj.response.ok);
return Promise.all(responses.map(obj => {
return {
url: obj.url,
config: obj.response.json()
};
}));
return responses.filter(obj => obj?.config);
}).then(configs => {
const selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0];
return Promise.resolve(selection?.url);
return selection?.url;
}).catch(error => {
console.log(error);
return Promise.resolve();
});
}