ton-connect / sdk

SDK for TON Connect 2.0 — a comprehensive communication protocol between wallets and apps in TON ecosystem
Apache License 2.0
329 stars 96 forks source link

[UI]: How to catch the `TON_CONNECT_SDK_ERROR` error? #202

Open bchevalier opened 4 months ago

bchevalier commented 4 months ago

Your Question

My application is triggering tons of TON_CONNECT_SDK_ERROR errors with the message Operation aborted. However, those are all uncaught promise exceptions. How can I catch them to handle them properly?

Here is the code of the application, note that I am handling errors in the status change:

    this.tonConnectUI = new TonConnectUI({
      manifestUrl: `${myUrl}/tonconnect-manifest.json`,
    });

    this.tonConnectUI.onStatusChange(
      async (status: ConnectedWallet | null) => onStatusChange,
      (error: TonConnectError) => {
        trackError('WalletConnectError', {
          name: error.name,
          message: error.message,
        });
      },

Context

No response

What have you tried so far?

No response

Relevant Code or Commands

No response

Documentation Check

0x1337z commented 4 months ago

Same issue here

Sotatek-CanPham commented 4 months ago

same issue in Nextjs

zapletnev commented 4 months ago

The same

abhiyana commented 3 months ago

Did you get any solution? I am facing same issue.

bchevalier commented 3 months ago

@abhiyana

One possible way to catch it is by using the javascript unhandledrejection event and identifying the ton connect sdk error:

function isTonConnectSdkError(error: Error | string) {
  const tonConnectError = 'TON_CONNECT_SDK';
  if (typeof error === 'string') {
    return error.includes(tonConnectError);
  }

  return error.message?.includes(tonConnectError);
}

window.addEventListener('unhandledrejection', function (rejection: PromiseRejectionEvent) {
  // handle rejection
  if (isTonConnectSdkError(rejection.reason)) {
    // ignore TonConnect sdk errors, they are handlded by sentry
    return;
  }
});

It's not ideal though because it does not prevent third party dependencies from catching those unhandled promise errors as well (such as analytics or error aggregation components).

SharmilaBlessy27 commented 1 month ago

Hi everyone,

I’m using the tonconnect/ui-react package to trigger wallet connections in my project. The wallet connection is established successfully, but after 5 to 10 minutes, I start seeing the following error:

[TON_CONNECT_SDK_ERROR] TonConnectError Operation aborted Error: Operation aborted at abortController.signal.addEventListener.once (http://localhost:3000/static/js/bundle.js:64575:14) at signal.addEventListener.once (http://localhost:3000/static/js/bundle.js:64414:108) ...

Initially, everything works fine, but after some time, this error pops up. It seems to be related to the connection aborting after a certain amount of inactivity.

Has anyone encountered this issue or knows what could be causing the connection to abort after a delay? Please any one help me to resolve this?

khanhhaquang commented 1 month ago
image
chengxianlov commented 1 month ago

the same image

meri-maki commented 1 month ago

same thing i want to implement cannot catch TonConnectUIProvider errors.....

Tvenus commented 1 month ago

The same

minhkhoi8888 commented 1 month ago

the same

runi-k commented 3 weeks ago

same issue

SaeedSoheili commented 2 weeks ago

i have same issue

Tvenus commented 2 weeks ago

I solved that problem.

uintptrs commented 2 weeks ago

I solved that problem.

Would you share the step's you taken for solving this issue?

Tvenus commented 2 weeks ago

@uintptrs

layout.tsx

import { TonConnectUIProvider } from '@tonconnect/ui-react';

...

==================================================

And create tonconnect-manifest.json in the "public" folder.

Structure of tonconnect-manifest.json

  {
"url": "your site url", 
"name": "name",
"iconUrl": "iconUrl"
 }