From 60e8cea113d828ae45b352c5d764818f89108426 Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Sat, 20 Apr 2024 18:56:37 +0100 Subject: [PATCH] fix: use unsealed result should fail if request fails --- src/client/hooks/useUnsealedResult.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/hooks/useUnsealedResult.ts b/src/client/hooks/useUnsealedResult.ts index 443fe50c..aa3abcb5 100644 --- a/src/client/hooks/useUnsealedResult.ts +++ b/src/client/hooks/useUnsealedResult.ts @@ -5,10 +5,14 @@ export const useUnsealedResult = (sealedResult?: string) => { return useQuery({ queryKey: ['event', sealedResult], queryFn: async () => { - return fetch('/api/decrypt', { + const response = await fetch('/api/decrypt', { method: 'POST', body: JSON.stringify({ sealedResult }), - }).then((res) => res.json()); + }); + if (response.status !== 200) { + throw new Error('Failed to unseal result: ' + response.statusText); + } + return await response.json(); }, enabled: Boolean(sealedResult), });