diff --git a/src/app/hooks/use-attestors.ts b/src/app/hooks/use-attestors.ts index cfd16042..d07bd596 100644 --- a/src/app/hooks/use-attestors.ts +++ b/src/app/hooks/use-attestors.ts @@ -18,6 +18,11 @@ export function useAttestors(): UseAttestorsReturnType { const coordinatorGroupPublicKeyEndpoint = `${attestorAPIURLs[0]}/tss/get-group-publickey`; try { const response = await fetch(coordinatorGroupPublicKeyEndpoint); + + if (!response.ok) { + throw new Error(`HTTP Error! Status: ${response.status}`); + } + const attestorGroupPublicKey = await response.text(); return attestorGroupPublicKey; } catch (error) { @@ -31,20 +36,30 @@ export function useAttestors(): UseAttestorsReturnType { userNativeSegwitAddress: string ): Promise { const createPSBTURLs = attestorAPIURLs.map(url => `${url}/app/create-psbt-event`); - const requests = createPSBTURLs.map(async url => { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - fetch(url, { - method: 'POST', - headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, - body: JSON.stringify({ - uuid, - closing_psbt: closingPSBT, - mint_address: userNativeSegwitAddress, - chain: ethereumAttestorChainID, - }), + try { + const requests = createPSBTURLs.map(async url => { + const response = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, + body: JSON.stringify({ + uuid, + closing_psbt: closingPSBT, + mint_address: userNativeSegwitAddress, + chain: ethereumAttestorChainID, + }), + }); + + if (!response.ok) { + throw new Error(`HTTP Error! Status: ${response.status}`); + } + + return response.json(); }); - }); - await Promise.all(requests); + + await Promise.all(requests); + } catch (error) { + throw new AttestorError(`Error sending closing transaction to Attestors: ${error}`); + } } return {