I had a issue with my app shutting down when discord wasn't launched on desktop because of RPC.
rpc.login({
clientId: "clientid"
})
.catch(console.error);
Now when I added the catch block it doesn't shut down when it cannot connect but it shows a pretty long error to the user, which I would like to hide or replace with a smaller console log like "RPC offline" or something
Error: Could not connect
at Socket.onerror (C:\snapshot\test\node_modules\discord-rpc\src\transports\ipc.js:32:16)
at Object.onceWrapper (node:events:514:26)
at Socket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
ofcourse i tried to use normal try-catch and only .catch(error)
instead of .catch(console.error)
but that doesn't seem to catch the unsuccessful connection and just shuts down the script again.
The
rpc.login
method returns a Promise which if fails to fulfil ( rejected promise ) throws an error, your approach was absolutely correct to usePromise.prototype.catch
&try/catch
and from what I can understand by your questionYou can simply pass a
console.log
statement when you catch the error in your promise like so:Or use
try/catch/finally
- ( Suggested if retrying to login multiple times )