title: Proper Handling of fetch errors for Mongoose?
body: <p>This is a pure best practice question. I am pretty new to Node and Mongoose. I absolutely love the technology and have been cranking away on a project to build a JSON-backed API for an app that I'm building. </p>
  
  <p>I am finding that I am continuously repeating code when I fetch objects from my database. For example:</p>
  
  <pre><code>Playlist.findById(req.params.id, function(err,playlist){
    if (err)
      return res.json({error: "Error fetching playlist"});
    else if (!playlist)
      return res.json({error: "Error finding the playlist"});
  
    //Actual code being performed on the playlist that I'm fetching
  });
  </code></pre>
  
  <p>The error handling at the top of the function call is annoying because I have to repeat that code for every call to the database... or so I think.</p>
  
  <p>I thought about using a callback like:</p>
  
  <pre><code>var fetchCallback = function(err,objOrDoc,callback){
    //Handle the error messages
    callback(objOrDoc);
  };
  </code></pre>
  
  <p>However, this approach would mess up my sequential flow since I would have to define the callback function before I performed the fetch. So, if I had a lot of database queries chained together, I would have to place the callbacks in reverse order, which is far from ideal in a clean-coding perspective.</p>
  
  <p>I'm wondering if anyone has run into this issue and has any best practices for cutting down on the repetition. </p>
  
  <p>I'm also using the express framework, so if there's a helpful way to handle it in express, I'd be interested to know, too.</p>