Skip to content

Commit

Permalink
fix: add checks to see if http responses are ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Mar 21, 2024
1 parent d8b4f97 commit 5e202c4
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/app/hooks/use-attestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,20 +36,30 @@ export function useAttestors(): UseAttestorsReturnType {
userNativeSegwitAddress: string
): Promise<void> {
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 {
Expand Down

0 comments on commit 5e202c4

Please sign in to comment.