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

feat: implement enhancedFetch for improved error handling and fallback support

This commit is contained in:
sunnylqm
2025-08-30 11:45:47 +08:00
parent f01df80b5c
commit 0d145bf8a0
4 changed files with 37 additions and 5 deletions

View File

@@ -33,7 +33,7 @@ const ping =
: async (url: string) => {
let pingFinished = false;
return Promise.race([
fetch(url, {
enhancedFetch(url, {
method: 'HEAD',
})
.then(({ status, statusText }) => {
@@ -73,3 +73,34 @@ export const testUrls = async (urls?: string[]) => {
logger('all ping failed, use first url:', urls[0]);
return urls[0];
};
// export const isAndroid70AndBelow = () => {
// // android 7.0 and below devices do not support letsencrypt cert
// // https://letsencrypt.org/2023/07/10/cross-sign-expiration/
// return Platform.OS === 'android' && Platform.Version <= 24;
// };
export const enhancedFetch = async (
url: string,
params: Parameters<typeof fetch>[1],
isRetry = false,
) => {
return fetch(url, params)
.then((r) => {
if (r.ok) {
return r;
}
throw new Error(`${r.status} ${r.statusText}`);
})
.catch((e) => {
logger('fetch error', url, e);
if (isRetry) {
throw e;
}
logger('trying fallback to http');
return enhancedFetch(url.replace('https', 'http'), params, true);
});
};