title: Error handling with Mongoose
body: <p>I am an absolute NodeJS beginner and want to create a simple REST-Webservice with Express and Mongoose.</p>
  
  <p>Whats the best practice to handle errors of Mongoose in one central place?</p>
  
  <p>When anywhere an database error occurs I want to return a Http-500-Error-Page with an error message:</p>
  
  <pre><code>if(error) {
    res.writeHead(500, {'Content-Type': 'application/json'});
    res.write('{error: "' + error + '"}');
    res.end();
  }
  </code></pre>
  
  <p>In the old tutorial <a href="http://blog-next-stage.learnboost.com/mongoose/">http://blog-next-stage.learnboost.com/mongoose/</a> I read about an global error listener:</p>
  
  <pre><code>Mongoose.addListener('error',function(errObj,scope_of_error));
  </code></pre>
  
  <p>But this doesn't seem to work and I cannot find something in the <a href="http://mongoosejs.com/docs/guide.html">official Mongoose documentation</a> about this listener. Have I check for errors after every Mongo request?</p>