1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 12:11:39 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

catch network error

This commit is contained in:
sunny.luo
2024-12-02 16:16:18 +08:00
parent d4f21a39f5
commit 946a5db7e9

View File

@@ -41,12 +41,12 @@ const ping =
Promise.race([
fetch(url, {
method: 'HEAD',
}).then(({ status }) => (status === 200 ? url : null)),
})
.then(({ status }) => (status === 200 ? url : null))
.catch(() => null),
new Promise(r => setTimeout(() => r(null), 2000)),
]);
const canUseGoogle = ping('https://www.google.com');
export function joinUrls(paths: string[], fileName?: string) {
if (fileName) {
return paths.map(path => 'https://' + path + '/' + fileName);
@@ -57,8 +57,5 @@ export const testUrls = async (urls?: string[]) => {
if (!urls?.length) {
return null;
}
if (await canUseGoogle) {
return urls[0];
}
return promiseAny(urls.map(ping)).catch(() => null);
};