[DiscordApiError] How to handle global error(api and wss)?
3lang3 opened this issue · comments
Which package has the bugs?
The core library
Issue description
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
@aiko-chan-ai Hi, hope I can get your help 🥹🥹
How to catch all errors
How to safely destroy instances
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
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