Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DiscordApiError] How to handle global error(api and wss)? #1120

Open
3 tasks done
3lang3 opened this issue Apr 2, 2024 · 3 comments
Open
3 tasks done

[DiscordApiError] How to handle global error(api and wss)? #1120

3lang3 opened this issue Apr 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@3lang3
Copy link

3lang3 commented Apr 2, 2024

Which package has the bugs?

The core library

Issue description

image

Code sample

this.on('error', (err) => {
  console.log(`❌ Error: ${err?.message}`)
  throw new TaskError('discord:unknow', err?.message)
})

I tried to use the above code, but I still couldn't catch similar errors, including requests in wss, and still couldn't interrupt the wss connection after calling destroy methods.

Package version

3.1.4

Node.js version

20.11.1

Operating system

MacOS

Priority this issue should have

High (immediate attention needed)

Checklist

  • I have searched the open issues for duplicates.
  • I have shared the entire traceback.
  • I am using a user token (and it isn't visible in the code).

Additional Information

No response

@3lang3 3lang3 added the bug Something isn't working label Apr 2, 2024
@3lang3
Copy link
Author

3lang3 commented Apr 2, 2024

@aiko-chan-ai Hi, hope I can get your help 🥹🥹
How to catch all errors
How to safely destroy instances

@TheDevYellowy
Copy link
Contributor

What I normally do is throw the following code into another file and then in my index.js call it like require("./antiCrash.js")();

module.exports = () => {
    process.on('unhandledRejection', (reason, p) => {
        console.log(' [Anti Crash] ::  Unhandled Rejeciton/Catch');
        console.log(reason, p)
    })

    process.on('uncaughtException', (e, o) => {
        console.log(' [Anti Crash] ::  Uncaught Exception/Catch');
        console.log(e, o)
    })

    process.on('uncaughtExceptionMonitor', (err, origin) => {
        console.log(' [AntiCrash] ::  Uncaught Exception/Catch (MONITOR)');
        console.log(err, origin);
    });

    process.on('multipleResolves', (type, promise, reason) => {
        console.log(' [AntiCrash] ::  Multiple Resolves');
        console.log(type, promise, reason);
    });
}

But when you use the throw keyword it kills the node process

@3lang3
Copy link
Author

3lang3 commented May 22, 2024

What I normally do is throw the following code into another file and then in my index.js call it like require("./antiCrash.js")();

module.exports = () => {
    process.on('unhandledRejection', (reason, p) => {
        console.log(' [Anti Crash] ::  Unhandled Rejeciton/Catch');
        console.log(reason, p)
    })

    process.on('uncaughtException', (e, o) => {
        console.log(' [Anti Crash] ::  Uncaught Exception/Catch');
        console.log(e, o)
    })

    process.on('uncaughtExceptionMonitor', (err, origin) => {
        console.log(' [AntiCrash] ::  Uncaught Exception/Catch (MONITOR)');
        console.log(err, origin);
    });

    process.on('multipleResolves', (type, promise, reason) => {
        console.log(' [AntiCrash] ::  Multiple Resolves');
        console.log(type, promise, reason);
    });
}

But when you use the throw keyword it kills the node process

This is not a good solution, catching the corresponding error should be recommend, but we can't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@3lang3 @TheDevYellowy and others