Displaying errors with node.js
-
30-10-2019 - |
Вопрос
I want to be able to send a friendly error message to my user whenever I cannot connect to my MongoDB server from inside node.js, instead of just having node.js
freaking out as it does right now.
Apparently this won't work as I cannot access the response variable from outside a route method (app.get('/' ...
), so what should I do instead?
No need to display something fancy, but just informing the user about a temporary problem would be amazing.
mongoose.connect('mongodb://localhost/test', function(err) {
if (err) {
//response.send('Temporary problem', 500);
}
});
// Routes
app.get('/', index.index);
//... And so on
Нет правильного решения
Не связан с StackOverflow