Is there a way to wrap an await/async try/catch block to every function?
<p>So i'm using express.js and looking into using async/await with node 7. Is there a way that I can still catch errors but get rid of the try/catch block? Perhaps a function wrapper? I'm not sure how this would actually execute the function's code and also call <code>next(err)</code>.</p>

<pre><code>exports.index = async function(req, res, next) {
  try {
    let user = await User.findOne().exec();

    res.status(200).json(user);
  } catch(err) {
    next(err);
  }
}
</code></pre>

<p>Something like this...?</p>

<pre><code>function example() {
   // Implements try/catch block and then handles error.
}

exports.index = async example(req, res, next) {
  let user = await User.findOne().exec();
  res.status(200).json(user);
}
</code></pre>

<p>EDIT: </p>

<p>Something more similar to this:</p>

<pre><code>var wrapper = function(f) {
    return function() {
        try {
            f.apply(this, arguments);
        } catch(e) {
            customErrorHandler(e)
        }
    }
}
</code></pre>

<p>This would somehow handle the try/catch block but doesn't work:</p>

<pre><code>exports.index = wrapper(async example(req, res, next) {
  let user = await User.findOne().exec();
  res.status(200).json(user);
});
</code></pre>

<p>See <a href="https://stackoverflow.com/questions/11742067/is-there-a-way-to-add-try-catch-to-every-function-in-javascript">Is there a way to add try-catch to every function in Javascript?</a> for the non-async example.</p>