H
H
heducose2017-07-22 19:21:15
MongoDB
heducose, 2017-07-22 19:21:15

Error handling when Mongo crashes - how to implement?

How to make an error output when the base has fallen? At the moment, everything is just spinning for me, and then the entire server crashes if there is a request to Monga, and Monga itself is not running. I am using Mongoose
My Controller:

exports.secret = function (req, res) {
  User.findById(req.user.sub, function (err, user) {
    if (err) {
      res.send('DB is broken')
      return
    }
    if (user) {
      res.send({
        eee: req.user,
        hi: 'SECRET test authorization of registered user'
      })
    } else {
      res.send('user not found')
    }
  })
}

I suspect that I missed something in other parts of the code on the server. How to fix it, where to look?
And at the same time tell me what to read on the topic of error handling? The logic of this process is hard for me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question