title: Try-Catch Not Handling Errors Properly
body: <p>I have this try-catch block which is supposed to catch any errors encountered while connecting to a Mongo Database, and return the status of &quot;Unauthorised&quot;. However, Express crashes in the backend although I am handling the errors if I turn off the MongoDB engine for testing. Shouldn't the errors be handled properly? (I am not using the err code as of now for testing.)</p>
  <pre><code>app.post('/api/login', (req, res) =&gt; {
    id = req.body.account
    var query = {_id: id}
    try {
      db.collection(&quot;Users&quot;).findOne(query, (err, result) =&gt; {
        if (result) {
          nonce = noncef()
          var upvalues = { $set: {nonce: nonce} }
          db.collection(&quot;Users&quot;).updateOne(query, upvalues, (err, result) =&gt; {
            if (result) {
              res.send(`${nonce}`)
            }
          })
        }
      })
    }
    catch(err) {
      res.status(401).send('Unauthorized')
    }
  })
  </code></pre>