Failing 'GET' request tests for Issue Tracker

I’m unable to solve the issue at hand. There is a minor code error in the Query Handler as shown in the console screenshot below.

Not sure where the Query was already executed. I’d really appreciate it if someone can look into this.

solution: https://replit.com/@usmanthrobsdrum/boilerplate-project-issuetracker-1

Live app link: https://boilerplate-project-issuetracker-1.usmanthrobsdrum.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

Challenge: Issue Tracker

Link to the challenge:

Googling the error led to a post on SO and comments that provided some hints. One, the query is executing multiple times, and two, a common cause is mixing the various async methods.

This bit of code (and others…)

      await Issue.find(query, (err,issues)=>{
        if(err){
          res.status(400).send(err)
        }
        res.json(issues)
      })

is the problem. You are using an await and a callback (err, issues) => {...} which results in running the query twice (I’ll leave the why as an exercise for the reader, since I don’t know right now but I assume that the query runs and is resolved for the callback and the await). Converting to just await kills the error. I’m sure that converting to just a callback would also work.

So, just go through and convert all your asynchronous calls to either use async or a callback, but not both on the same call.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.