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

throw error

This commit is contained in:
sunnylqm
2024-07-24 17:06:49 +08:00
parent 3355751bd5
commit 454fc28c08
3 changed files with 33 additions and 5 deletions

View File

@@ -37,6 +37,15 @@ export const PushyProvider = ({
const [lastError, setLastError] = useState<Error>();
const lastChecking = useRef(0);
const throwErrorIfEnabled = useCallback(
(e: Error) => {
if (options.throwError) {
throw e;
}
},
[options.throwError],
);
const dismissError = useCallback(() => {
setLastError(undefined);
}, []);
@@ -115,9 +124,16 @@ export const PushyProvider = ({
} catch (e: any) {
setLastError(e);
alertError('更新失败', e.message);
throwErrorIfEnabled(e);
}
},
[alertError, client, options.updateStrategy, alertUpdate],
[
client,
options.updateStrategy,
alertUpdate,
alertError,
throwErrorIfEnabled,
],
);
const downloadAndInstallApk = useCallback(
@@ -141,6 +157,7 @@ export const PushyProvider = ({
} catch (e: any) {
setLastError(e);
alertError('更新检查失败', e.message);
throwErrorIfEnabled(e);
return;
}
if (!info) {
@@ -195,12 +212,13 @@ export const PushyProvider = ({
);
}
}, [
alertError,
client,
downloadAndInstallApk,
downloadUpdate,
alertError,
throwErrorIfEnabled,
options.updateStrategy,
alertUpdate,
downloadAndInstallApk,
downloadUpdate,
]);
const markSuccess = client.markSuccess;