Browse Source

added comments, simplified logic

pull/850/head
Stephen Hess 8 years ago
parent
commit
080eb269eb
  1. 6
      service/http_json.js

6
service/http_json.js

@ -6,6 +6,7 @@ const logger = require( 'pelias-logger' ).get( 'placeholder' );
const ServiceConfiguration = require('./configurations/ServiceConfiguration'); const ServiceConfiguration = require('./configurations/ServiceConfiguration');
// superagent doesn't exposed the assembled GET request, so synthesize it
function synthesizeUrl(serviceConfig, req) { function synthesizeUrl(serviceConfig, req) {
const parameters = _.map(serviceConfig.getParameters(), (value, key) => { const parameters = _.map(serviceConfig.getParameters(), (value, key) => {
return `${key}=${value}`; return `${key}=${value}`;
@ -79,10 +80,11 @@ module.exports = function setup(serviceConfig) {
return; return;
} }
// if json was returned then just return it
if (response.type === 'application/json') { if (response.type === 'application/json') {
return callback(null, response.body); return callback(null, response.body);
}
} else {
if (do_not_track) { if (do_not_track) {
logger.error(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`); 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}`); return callback(`${serviceConfig.getBaseUrl()} [do_not_track] could not parse response: ${response.text}`);
@ -91,8 +93,6 @@ module.exports = function setup(serviceConfig) {
return callback(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`); return callback(`${synthesizeUrl(serviceConfig, req)} could not parse response: ${response.text}`);
} }
}
}); });
}; };

Loading…
Cancel
Save