title: After res.send() event in Restify?
body: <p>I'm trying to add Bugsnag to my Node Restify service. We have a ton of routes already and such so I'm trying not to add Bugsnag calls all over our code base and I'm also trying to do something global so there's never a mistake where a dev forgets to add the error reporting.</p>
  
  <p>Conceptually I want <em>after</em> any <code>res.send()</code> to get the status code. If the statusCode is >=400 i want to notify Bugsnag by calling <code>Bugsnag.notify</code>. I already check for errors everywhere so no errors ever show up to the clients (browsers, phones, etc) but they do get sent, for example, <code>res.send(401, { message: 'You dont have permission to do that' })</code> which I'd like to be able to hook into and pass who tried to do that, what route, etc. Problem is I can't get the <code>after</code> event to fire at all:</p>
  
  <pre><code>server.on('after', function (req, res, route, error) {
    console.log('AFTER')
  });
  </code></pre>
  
  <p>I think I misunderstand what <code>after</code> is for. It's at the top of my <code>index.js</code> before any routes or other middleware (<code>server.use</code>) is defined.</p>
  
  <p>My general code structure looks something like:</p>
  
  <pre><code>  server.post('/foo', function (req, res, next) {
      FooPolicy.create(req, function (err) {
        if (err) return res.send(err.code, err.data);
        FooController.create(req.params, function (response) {
          res.send(response.code, response.data)
          next();
        });
      });
    });
  </code></pre>
  
  <p>FooPolicy == checking permissions<br>
  FooController == actually creating the model/data</p>