Hello! I have a discord bot and it’s on a boost app and everything but I keep getting, “UnhandledPromiseRejectionWarning: Error: Did not receive X-CSRF-TOKEN” and I don’t know what it means or how to fix it… Could anyone help?

Can you share the code around where the error was rejected / thrown?

It’s not a actual certain part of the code… It isn’t saying there is a error in any certain spot… So I am guessing it’s with the whole thing. This is the whole error:

```(node:414) UnhandledPromiseRejectionWarning: Error: Did not receive X-CSRF-TOKEN
    at /rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/noblox.js/4.6.1/node_modules/noblox.js/lib/util/getGeneralToken.js:26:15
    at tryCatcher (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/rbd/pnpm-volume/ba8ad2ea-2200-4315-8458-c8ccd0602591/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)
(node:414) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:414) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

You should add a .catch method to functions that returns a Promise. It’s really hard to debug that information when you don’t know where it’s coming from.

So what should I do?

Where ever in your code where you call something from bluebird or noblox.js that returns a promise you should add a catch method to it.

function returnsPromise ()
  return new Promise(async (resolve, reject) => {
    reject(new Error("Hello World"));

returnsPromise(); // will reject

// do this instead.

returnsPromise().catch(error => console.log(new Error(error.message).stack));

That will help you debug promises.

1 Like

I feel like you have a middleware that’s causing it, would you mind sharing your package.json or list packages that start with express- and other things you think are middleware(basically everything you write app.use with)

Looks like it’s an error from the express csurf middleware. Can you share any code that uses that?

Are you perhaps using noblox? If so, update the package to it’s latest version (4.6.3). You should also make sure other packages are not outdated.

1 Like

Yes. This is a noblox error. Update your packages

This is about 3 months old. OP may have already solved their problem.


Yeah. I came across this problem and this helped me fix it.