r3volved / api-swgoh-help

Connection wrapper for api.swgoh.help
MIT License
34 stars 4 forks source link

Error with URL of fetch request #7

Closed DavideVitali closed 3 years ago

DavideVitali commented 3 years ago

Expected behaviour

swapi.fetch( 'player', payload ) should return a promise.

Actual behaviour

Following code results in error:

const swhelp = require('api-swgoh-help');
const secrets = require('./secrets.json');

async function getPlayers(allyCodes) {
    const swapi = new swhelp({
        "username": secrets.username,
        "password": secrets.password
    });

    let { result, error, warning } = await swapi.fetch( 'player',  allyCodes );

    console.log(result);
}

getPlayers([914315138]);

Stack trace:

(node:4340) UnhandledPromiseRejectionWarning: TypeError: Only absolute URLs are supported at getNodeRequestOptions (C:\Users\Davide\Documents\repos\test\node_modules\node-fetch\lib\index.js:1305:9) at C:\Users\Davide\Documents\repos\test\node_modules\node-fetch\lib\index.js:1410:19 at new Promise (<anonymous>) at SwgohHelp.fetch (C:\Users\Davide\Documents\repos\test\node_modules\node-fetch\lib\index.js:1407:9) at getPlayers (C:\Users\Davide\Documents\repos\test\index.js:10:50) at Object.<anonymous> (C:\Users\Davide\Documents\repos\test\index.js:18:1) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14)

Installed dependencies:


  "dependencies": {
    "api-swgoh-help": "^3.3.0",
    "node-fetch": "^2.6.1"
  },
DavideVitali commented 3 years ago

Ok, I was referring to help in the npm page... I should have called 'swapi.fetchPlayer' instead, as 'swapi.fetch' calls the node-fetch method. Now I'm getting another error (malformed payload), but I'll investigate further before opening another issue.