I'm making a Discord bot, now I'm working at commands that interact with Geometry Dash API. I'm using axios to fetch the level info, and when I type the existing ID, I get the correct and working result. But if I'll type the incorrect ID, I get a -1 error. I tried to handle this error, but nothing works. What should I do?
const axios = require("axios");
exports.run = (client, message, args) => {
const id = args[0];
axios.get(`https://gdbrowser.com/api/level/${id}`).then((response) => {
try {
const { data } = response;
const { name, id, description, author, difficulty, downloads, length, stars, orbs, diamonds, featured, epic, gameVersion, version, coins, verifiedCoins, starsRequested, ldm, objects } = data;
message.channel.send(`Name: ${name}\nID: ${id}\nDesc: ${description}\nAuthor: ${author}\nDifficulty: ${difficulty}\nDownloads: ${downloads}\nLength: ${length}\nStars: ${stars}\nOrbs: ${orbs}\nDiamonds: ${diamonds}\nFeatured: ${featured}\nEpic: ${epic}\nGame Ver: ${gameVersion}\nVersion: ${version}\nCoins: ${coins}\nVerified Coins: ${verifiedCoins}\nStarsReq: ${starsRequested}\nLDM: ${ldm}\nObjects: ${objects}`)
} catch (e) {
if(data === -1) {
return;
}
}
})
}
Already fixed it. -1 was the error.response.data.