Skip to content

Commit

Permalink
api: measure elapsed time
Browse files Browse the repository at this point in the history
return it in objects
  • Loading branch information
wmertens committed Feb 10, 2021
1 parent 31f5d15 commit 500a237
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions source/git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 500a237

Please sign in to comment.