Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add checks to see if http responses are ok #57

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.text();
});
});
await Promise.all(requests);

await Promise.all(requests);
} catch (error) {
throw new AttestorError(`Error sending closing transaction to Attestors: ${error}`);
}
}

return {
Expand Down
Loading