Skip to content

Commit

Permalink
fix: Adding handler for custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
y3fers0n committed Oct 31, 2024
1 parent ff8bb66 commit f456f52
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/ton/TonBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ export class TonBridge implements TonConnectBridge {

return { result, id: message.id.toString() };
} catch (e) {
// Parse general RPC rejection errors to ton
if ((e as any)?.code === 4001) {
return {
error: {
message: 'User Rejected the transaction',
code: 300,
},
id: String(message.id),
};
}

// If there are too many requests
if ((e as any)?.code === -32002) {
return {
error: {
message: 'Bad request, a transaction is already pending',
code: 1,
},
id: String(message.id),
};
}

// Set default error code if needed
if (
(e as WalletResponseError['error']) &&
![0, 1, 100, 300, 400].includes(
(e as WalletResponseError['error']).code,
)
) {
(e as WalletResponseError['error']).code = 0;
}

return {
error: e as WalletResponseError['error'],
id: String(message.id),
Expand Down

0 comments on commit f456f52

Please sign in to comment.