Skip to content

Commit

Permalink
Merge pull request #143 from zama-ai/add-more-errors
Browse files Browse the repository at this point in the history
feat: add more granularity on errors in reencrypt
  • Loading branch information
immortal-tofu authored Dec 4, 2024
2 parents 0df749f + 34acb14 commit aaa84c2
Showing 1 changed file with 19 additions and 3 deletions.
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}`,
);
}
} 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

0 comments on commit aaa84c2

Please sign in to comment.