hidjou / classsed-graphql-mern-apollo

408 stars 255 forks source link

deleteComment Mutation Bug #36

Open LoohAugustine opened 3 years ago

LoohAugustine commented 3 years ago

I found a bug in the deleteComment Mutation.

When I tried to detete a non existing comment, an exception error was not caught. That is because the findIndex function returns -1 if the entry is not found. When you try to access the index in the if condition statement, the exception is thrown.

To catch this error, I introduced a new if block to check if commentIndex is >= 0 before executing the delete command and throw a new UserInputError if not. That fixed the issue.

Thanks a lot for your tutorial, it's doing wonders for me.