hotbear1110 / botbear

Dank bot, idk
GNU General Public License v3.0
19 stars 16 forks source link

401 after running the bot on dev setup #49

Open KUNszg opened 2 years ago

KUNszg commented 2 years ago

After correctly setting up the .env file, running the bot spams the console with error below.

obraz

I traced it back to be this helix API request in tools.js file

const userData = await got(`https://api.twitch.tv/helix/users?id=${streamer.uid}`, {
    headers: {
        'client-id': process.env.TWITCH_CLIENTID,
        'Authorization': process.env.TWITCH_AUTH
    },
    timeout: 10000
}).json();

and it seems like it has to do something with empty fields in the database, also I noticed that a new row gets inserted into the streamers table each time the bot is launched, and that row has empty username, uid fields etc. so that might contribute to errors.

Either way this error is not fatal and the instance continues to run, but it's worth to take a look at it.

hotbear1110 commented 2 years ago

The new rows each time the bot was launched, was due to the .env uid being a string while the db uid is an int, that got fixed in commit dc6ba9156bfc3589e925f806125afccaca977d46 As for the 401 error, I still get them from time to time. Still not 100% sure what causes them

hotbear1110 commented 2 years ago

From what I can test, it seems like we should only get 401 response when the client-id or Auth is missing. Unsure why that would happen.

KUNszg commented 2 years ago

From what I can test, it seems like we should only get 401 response when the client-id or Auth is missing. Unsure why that would happen.

Good solution to it would be making the http calls optional and make them work only when the credentials are valid, also finding a more precise way to track these errors would be good practice, like which request failed at what line and log of the credentials that got inputted etc.