'I am making a discord.js bot and I want to know if there was an error

I am using the following code to figure out if there was an error. But I want to not run something if there was an error. I have tried to look it up and I could not find anything about it.

 member.roles.remove(role).catch((error) => {
    message.reply("I don't have permission to do that!");
});
message.channel.send("Removed role!");


Solution 1:[1]

You can do it like this-

member.roles.remove(role).then(() => message.channel.send("Role Removed")).catch(err => message.channel.send("I dont have perms."))

If there will be an error it will not run the code inside .then().

Solution 2:[2]

You can use a variable to accomplish this.

If there was an error, set the variable to true; else, the variable will remain false.

For your case:

let isError = false;
await member.roles.remove(role).catch((error) => {
    message.reply("I don't have permission to do that!");
    isError = true;
});
if(!isError){
    message.channel.send("Removed role!");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glitter
Solution 2