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

feat: add more granularity on errors in reencrypt #143

Merged
merged 1 commit into from
Dec 4, 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
22 changes: 19 additions & 3 deletions src/sdk/reencrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,32 @@ export const reencryptRequest =
throw new Error('Invalid public or private key', { cause: e });
}

let response;
let json;
try {
const response = await fetch(`${gatewayUrl}reencrypt`, options);
response = await fetch(`${gatewayUrl}reencrypt`, options);
if (!response.ok) {
throw new Error(
`Reencrypt failed: gateway respond with HTTP code ${response.status}`,
immortal-tofu marked this conversation as resolved.
Show resolved Hide resolved
);
}
} catch (e) {
throw new Error("Reencrypt failed: Gateway didn't respond", { cause: e });
}

try {
json = await response.json();
} catch (e) {
throw new Error("Gateway didn't response correctly", { cause: e });
throw new Error("Reencrypt failed: Gateway didn't return a JSON", {
cause: e,
});
}

if (json.status === 'failure') {
throw new Error("The reencryption didn't succeed", { cause: json });
throw new Error(
"Reencrypt failed: the reencryption didn't succeed for an unknown reason",
{ cause: json },
);
}

const client = new_client(kmsSignatures, userAddress, 'default');
Expand Down
Loading