Skip to content

Commit

Permalink
Merge pull request #31 from pelias/add-response-time
Browse files Browse the repository at this point in the history
feat(response): Return metadata object with response time
  • Loading branch information
orangejulius authored Oct 26, 2018
2 parents 2a3eee1 + cd93392 commit f844919
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions service.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ module.exports = function setup(serviceConfig) {

logger.debug(`${serviceConfig.getName()}: ${url_for_logging}`);

const startTime = Date.now();

request
.get(serviceConfig.getUrl(req))
.set(headers)
Expand Down Expand Up @@ -113,17 +115,21 @@ module.exports = function setup(serviceConfig) {
return;
}

const metadata = {
response_time: Date.now() - startTime
};

// if json was returned then just return it
if (response.type === 'application/json') {
return callback(null, response.body);
return callback(null, response.body, metadata);
}

if (do_not_track) {
logger.error(`${url_for_logging} [do_not_track] could not parse response: ${response.text}`);
return callback(`${url_for_logging} [do_not_track] could not parse response: ${response.text}`);
return callback(`${url_for_logging} [do_not_track] could not parse response: ${response.text}`, null, metadata);
} else {
logger.error(`${url_for_logging} could not parse response: ${response.text}`);
return callback(`${url_for_logging} could not parse response: ${response.text}`);
return callback(`${url_for_logging} could not parse response: ${response.text}`, null, metadata);
}

});
Expand Down

0 comments on commit f844919

Please sign in to comment.