'use strict';

var ResponseBuilder = require('./ResponseBuilder');

module.exports = function(promiseReturningHandlerFn, request, cb, CustomRespBuilderClass) {
   promiseReturningHandlerFn()
      .then(function(respBuilder) {
         // eslint-disable-next-line no-console
         console.log('completed with %s millis left', request.getContext().getRemainingTimeInMillis());
         cb(undefined, respBuilder.toResponse(request));
      })
      .catch(function(err) {
         var RB = CustomRespBuilderClass || ResponseBuilder,
             respBuilder = new RB().serverError().rb();

         // eslint-disable-next-line no-console
         console.log('ERROR:', err, err.stack);
         cb(undefined, respBuilder.toResponse(request));
      })
      .done();
};

@@ -61,16 +61,347 @@
 der');%0A%0A
+/**%0A * In our APIs, we often have errors that are several promises deep, and without this,%0A * it's hard to tell where the error actually originated (especially with AWS calls, etc).%0A * This will generally make error stack traces much more helpful to us, so we are making%0A * it a default.%0A */%0Arequire('q').longStackSupport = true;%0A%0A
 module.e

Enable Q's long stack support by default