module.exports = function(router) {
'use strict';

  var Media = require('../models/Media');

  router.route('/media')

    // get all the media (accessed at GET http://localhost:port/api/media)
    .get(function(req, res) {
      Media.find(function(err, models) {
        if (err)
          res.send(err);
        res.json(models);
      });
    })


    // create a media (accessed at POST http://localhost:port/api/media)
    .post(function(req, res) {

      // create a new instance of the Media model
      var model = new Media();

      // set the media attributes
      model.name        = req.body.name;
      model.description = req.body.description;
      model.active      = req.body.active;

      // save the media and check for errors
      model.save(function(err) {
        if (err)
          res.send(err);

        res.json({ message: 'Media created!' });
      });

    });


  router.route('/media/:media_id')

    // get the media with that id (accessed at GET http://localhost:port/api/media/:media_id)
    .get(function(req, res) {
      Media.findById(req.params.media_id, function(err, model) {
        if (err)
          res.send(err);
        res.json(model);
      });
    })


    // update the media with this id (accessed at PUT http://localhost:port/api/media/:media_id)
    .put(function(req, res) {

      // use our media model to find the media we want
      Media.findById(req.params.media_id, function(err, model) {

        if (err)
          res.send(err);

        // update the media info
        model.name        = req.body.name;
        model.description = req.body.description;
        model.active      = req.body.active;

        // save the model
        model.save(function(err) {
          if (err)
            res.send(err);

          res.json({ message: 'Media updated!' });
        });
      });
    })


    // delete the media with this id (accessed at DELETE http://localhost:port/api/media/:media_id)
    .delete(function(req, res) {
      Media.remove({
        _id: req.params.media_id
      }, function(err, model) {
        if (err)
          res.send(err);

        res.json({ message: 'Successfully deleted' });
      });
    });

};

@@ -786,33 +786,35 @@
         if (err)
+ %7B
 %0A
-
           res.se
@@ -813,32 +813,60 @@
   res.send(err);
+%0A          return;%0A        %7D
 %0A%0A        res.js
@@ -1138,32 +1138,33 @@
 n(err, model) %7B%0A
+%0A
         if (err)
@@ -1155,32 +1155,34 @@
         if (err)
+ %7B
 %0A          res.s
@@ -1183,32 +1183,143 @@
  res.send(err);%0A
+          return;%0A        %7D%0A%0A        if (!model) %7B%0A          res.sendStatus(404);%0A          return;%0A        %7D%0A%0A
         res.json
@@ -1603,32 +1603,34 @@
         if (err)
+ %7B
 %0A          res.s
@@ -1630,32 +1630,142 @@
   res.send(err);
+%0A          return;%0A        %7D%0A%0A        if (!model) %7B%0A          res.sendStatus(404);%0A          return;%0A        %7D
 %0A%0A        // upd
@@ -1993,32 +1993,34 @@
         if (err)
+ %7B
 %0A            res
@@ -2022,32 +2022,64 @@
   res.send(err);
+%0A            return;%0A          %7D
 %0A%0A          res.
@@ -2357,32 +2357,33 @@
 n(err, model) %7B%0A
+%0A
         if (err)
@@ -2374,32 +2374,34 @@
         if (err)
+ %7B
 %0A          res.s
@@ -2409,16 +2409,44 @@
 nd(err);
+%0A          return;%0A        %7D
 %0A%0A      

Add error handling to the routes