Skip to content

Commit f456f52

Browse files
committed
fix: Adding handler for custom errors
1 parent ff8bb66 commit f456f52

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/ton/TonBridge.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ export class TonBridge implements TonConnectBridge {
151151

152152
return { result, id: message.id.toString() };
153153
} catch (e) {
154+
// Parse general RPC rejection errors to ton
155+
if ((e as any)?.code === 4001) {
156+
return {
157+
error: {
158+
message: 'User Rejected the transaction',
159+
code: 300,
160+
},
161+
id: String(message.id),
162+
};
163+
}
164+
165+
// If there are too many requests
166+
if ((e as any)?.code === -32002) {
167+
return {
168+
error: {
169+
message: 'Bad request, a transaction is already pending',
170+
code: 1,
171+
},
172+
id: String(message.id),
173+
};
174+
}
175+
176+
// Set default error code if needed
177+
if (
178+
(e as WalletResponseError['error']) &&
179+
![0, 1, 100, 300, 400].includes(
180+
(e as WalletResponseError['error']).code,
181+
)
182+
) {
183+
(e as WalletResponseError['error']).code = 0;
184+
}
185+
154186
return {
155187
error: e as WalletResponseError['error'],
156188
id: String(message.id),

0 commit comments

Comments
 (0)