Skip to content

Commit 946a5db

Browse files
author
sunny.luo
committed
catch network error
1 parent d4f21a3 commit 946a5db

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const ping =
4141
Promise.race([
4242
fetch(url, {
4343
method: 'HEAD',
44-
}).then(({ status }) => (status === 200 ? url : null)),
44+
})
45+
.then(({ status }) => (status === 200 ? url : null))
46+
.catch(() => null),
4547
new Promise(r => setTimeout(() => r(null), 2000)),
4648
]);
4749

48-
const canUseGoogle = ping('https://www.google.com');
49-
5050
export function joinUrls(paths: string[], fileName?: string) {
5151
if (fileName) {
5252
return paths.map(path => 'https://' + path + '/' + fileName);
@@ -57,8 +57,5 @@ export const testUrls = async (urls?: string[]) => {
5757
if (!urls?.length) {
5858
return null;
5959
}
60-
if (await canUseGoogle) {
61-
return urls[0];
62-
}
6360
return promiseAny(urls.map(ping)).catch(() => null);
6461
};

0 commit comments

Comments
 (0)