commit f7d72bfc06fae1e122f0ef2d9d09e0321c86ca70
parent 51a1168f2eea237601bd6451014d4b38ef16f1b6
Author: Sebastian <sebasjm@taler-systems.com>
Date: Sat, 31 Jan 2026 09:33:08 -0300
fix #10953
Diffstat:
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/packages/web-util/src/hooks/useAsync.ts b/packages/web-util/src/hooks/useAsync.ts
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { opUnknownFailure } from "@gnu-taler/taler-util";
+import { opUnknownFailure, TalerError } from "@gnu-taler/taler-util";
import { useEffect, useState } from "preact/hooks";
/**
@@ -28,7 +28,7 @@ export function useAsync<Res>(
deps: Array<any> = [],
) {
const [data, setData] = useState<Res>();
- const [error, setError] = useState<unknown>();
+ const [error, setError] = useState<TalerError>();
useEffect(() => {
let unloaded = false;
@@ -40,7 +40,11 @@ export function useAsync<Res>(
})
.catch((error: unknown) => {
if (unloaded) return;
- setError(error);
+ if (error instanceof TalerError) {
+ setError(error);
+ } else {
+ setError(TalerError.fromException(error))
+ }
});
}
return () => {
@@ -48,7 +52,7 @@ export function useAsync<Res>(
};
}, deps);
- if (error) return opUnknownFailure(error);
+ if (error) return (error);
if (!data) return undefined;
return data;
}
@@ -102,7 +106,7 @@ export function useLongPolling<Res, Rt>(
const body = result ?? initial;
useEffect(() => {
- if (body === undefined) return;
+ if (body === undefined || body instanceof TalerError) return;
const _body = body;
const rt = shouldRetryFn(_body, retry.startMs ?? 0);