Skip to content

Commit

Permalink
feat: add more granularity on errors in reencrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu authored Dec 4, 2024
1 parent 0df749f commit f406095
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/sdk/reencrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,25 @@ 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 f406095

Please sign in to comment.