mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:11:39 +08:00
catch network error
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
Reference in New Issue
Block a user