diff --git a/source/git-api.js b/source/git-api.js index 8790fc3ef..981c5dff6 100644 --- a/source/git-api.js +++ b/source/git-api.js @@ -163,14 +163,22 @@ exports.registerApi = (env) => { { maxWait: 2000 } ); - const jsonResultOrFailProm = (res, promise) => - // TODO shouldn't this be a boolean instead of an object? - promise - .then((o) => res.json(o == null ? {} : o)) - .catch((err) => { - winston.warn('Responding with ERROR: ', JSON.stringify(err)); - res.status(400).json(err); - }); + const jsonResultOrFailProm = (res, promise) => { + const now = Date.now(); + return ( + // TODO shouldn't this be a boolean instead of an object? + promise + .then((o) => { + const elapsed = Date.now() - now; + if (o && typeof o === 'object') o._elapsed = elapsed; + return res.json(o == null ? {} : o); + }) + .catch((err) => { + winston.warn('Responding with ERROR: ', JSON.stringify(err)); + res.status(400).json(err); + }) + ); + }; const w = (fn) => (req, res) => new Promise((resolve) => resolve(fn(req, res))).catch((err) => {