From 080eb269eb6f5b86cb8b5b08d1330023930f34bc Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 2 May 2017 14:33:14 -0400 Subject: [PATCH] added comments, simplified logic --- service/http_json.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/service/http_json.js b/service/http_json.js index 7c9a5716..1fe0a984 100644 --- a/service/http_json.js +++ b/service/http_json.js @@ -6,6 +6,7 @@ const logger = require( 'pelias-logger' ).get( 'placeholder' ); const ServiceConfiguration = require('./configurations/ServiceConfiguration'); +// superagent doesn't exposed the assembled GET request, so synthesize it function synthesizeUrl(serviceConfig, req) { const parameters = _.map(serviceConfig.getParameters(), (value, key) => { return `${key}=${value}`; @@ -79,18 +80,17 @@ module.exports = function setup(serviceConfig) { return; } + // if json was returned then just return it if (response.type === 'application/json') { return callback(null, response.body); + } + if (do_not_track) { + logger.error(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`); + return callback(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`); } else { - if (do_not_track) { - logger.error(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`); - return callback(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`); - } else { - logger.error(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`); - return callback(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`); - } - + logger.error(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`); + return callback(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`); } });