mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-23 09:38:52 +08:00
bump version to 10.30.1 and enhance error handling in enhancedFetch function
This commit is contained in:
17
src/utils.ts
17
src/utils.ts
@@ -109,9 +109,16 @@ export const enhancedFetch = async (
|
||||
url: string,
|
||||
params: Parameters<typeof fetch>[1],
|
||||
) => {
|
||||
return fetch(url, params).catch(e => {
|
||||
log('fetch error', url, e);
|
||||
log('trying fallback to http');
|
||||
return fetch(url.replace('https', 'http'), params);
|
||||
});
|
||||
return fetch(url, params)
|
||||
.then(r => {
|
||||
if (r.ok) {
|
||||
return r;
|
||||
}
|
||||
throw new Error(`${r.status} ${r.statusText}`);
|
||||
})
|
||||
.catch(e => {
|
||||
log('fetch error', url, e);
|
||||
log('trying fallback to http');
|
||||
return fetch(url.replace('https', 'http'), params);
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user