0

I am trying to access the fortnite API using node.js. I have everything setup as specified in the documentation, but am getting these few errors:

Fortnite-API - Credentials Params OK
(node:3036) UnhandledPromiseRejectionWarning: #<Object>
(node:3036) 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:3036) [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.

The code I have so far is:

const Fortnite = require("fortnite-api");

let fortniteAPI = new Fortnite(
[
    "redacted",
    "redacted",
    "redacted",
    "redacted"  
],
{
    debug: true
}
);

fortniteAPI.login().then(() => {
fortniteAPI
    .checkPlayer("x got", "pc")
    .then(stats => {
        console.log(stats);
    })
    .catch(err => {
        console.log(err);
    });
});

This is my first time messing around with node.js on my own, so I have really no idea what is going on with these errors. I had attempted to google the errors but all the explanations either went way over my head or looked like they were written in a different language.

EDIT: For anyone viewing this later, my error was caused by having 2FA (2 factor authentication) enabled on my account. You are going to have to disable that completely. Also, will later find out that Fiddler 4 won't work after starting the game to get your Fortnite API key. I found some after hours of googling so I will leave them here:

CLIENT LAUNCHER TOKEN: MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=

FORTNITE CLIENT TOKEN: ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ=

(be sure to include the "=")

Revircs
  • 1,312
  • 3
  • 12
  • 23
  • You should not have posted your keys online. Now everyone can use them to access your Fortnite API account. Generate new ones as quickly as possible! – Bergi Oct 28 '18 at 20:50

2 Answers2

1

can you please put a catch in login promise like below. see whether you are able to catch error or not.

fortniteAPI.login().then(() => {
fortniteAPI
.checkPlayer("x got", "pc")
.then(stats => {
    console.log(stats);
})
.catch(err => {
    console.log(err);
});
}).catch((error)=>{console.log('error at login-->',error)});
R.Sarkar
  • 344
  • 2
  • 8
0

You are only handling errors on the inner checkPlayer promise, not on the login promise. Don't nest then calls when you don't need to, just chain them instead and install the error handler in the end:

fortniteAPI.login()
.then(() => fortniteAPI.checkPlayer("x got", "pc")
.then(stats => {
    console.log(stats);
}, err => {
    console.log(err);
});

That might not prevent the error, but it will handle it in your console.log(err) line instead of printing it as an unhandled rejection.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375