twitchtv / igdb-api-node

Nodejs Wrapper for IGDB.com API. Requires an API key. Get one at:
https://api.igdb.com/
MIT License
128 stars 15 forks source link

HTTP Status 400 error on specific company #25

Closed favna closed 6 years ago

favna commented 6 years ago

I have been using this package for my discord bot for a while now and today someone reported getting the following error to me: Error: HTTP Status 400 - https://api-2445582011268.apicast.io/companies/1659,?fields=name

Checking this company ID in the API Live Test I do get a result with status code 200:

All other companies I have tried return a result just fine, only company 1659 does not. Due to the error seemingly being related to the URL the request is sent to I figured I'd first create an issue here before letting it over to hoping the API gets updated to fix the issue.

I get my data from the API through the following snippet:

const igdbapi = require('igdb-api-node').default,

    async function run(msg) {
        const igdb = igdbapi(auth.igdbAPIKey),
            gameInfo = await igdb.games({
                'search': args.game,
                'fields': ['id', 'name', 'summary', 'rating', 'developers', 'publishers', 'genres', 'release_dates', 'platforms', 'cover', 'esrb', 'pegi'],
                'limit': 1,
                'offset': 0
            }),
            developerInfo = await igdb.companies({
                'ids': gameInfo.body[0].developers.concat(gameInfo.body[0].publishers),
                'fields': ['name']
            });
    }
krazyjakee commented 6 years ago

My suspicion as that this line has an empty item in the array: gameInfo.body[0].developers.concat(gameInfo.body[0].publishers)

Can you paste the response for the initial games query?

favna commented 6 years ago

I've found the bug and it was indeed on my end. Array.prototype.concat() put undefined from the publishers as the second value of the array of IDs. I was under the false impression that .concat() would filter undefined and null. I have ensured that this won't happen again and so can close this issue with this comment.

const companies = await gameInfo.body[0].publishers ? gameInfo.body[0].developers.concat(gameInfo.body[0].publishers) : gameInfo.body[0].developers,
    developerInfo = await igdb.companies({
        'ids': companies,
        'fields': ['name']
    });