sparc-commons
Advanced tools
Comparing version 0.2.25 to 0.2.26
@@ -6,2 +6,3 @@ /*jshint multistr: true */ | ||
var confResource = config.get('resource') | ||
var log = require('./logger').logger('[RESOURCE]') | ||
@@ -41,2 +42,3 @@ var resources = _.reduce(confResource, (acc, v, k) => { | ||
exports.requestResource = function requestResource(target, service, opts) { | ||
if (_.isUndefined(service)) { | ||
@@ -57,2 +59,4 @@ throw new Error(`Resource ${resource} invoked with undefined service parameter`) | ||
var resource = _.get(resources, target); | ||
var logStrategy = _.get(resource, 'logging', 'NEVER') | ||
console.log(logStrategy) | ||
var url = resource.url + '/' + resource[service]; | ||
@@ -108,4 +112,10 @@ var data = _.get(opts, 'data', {}); | ||
} else if (resp.statusCode == 200) { | ||
if(logStrategy === 'ALWAYS'){ | ||
log.info(`Got response ${_.get(resp, 'body')}`) | ||
} | ||
res(resp.body); | ||
} else { | ||
if(logStrategy !== 'NEVER'){ | ||
log.error(_.get(resp, 'body')) | ||
} | ||
var myError = new Error('Resource ' + target + ' replied with ' + resp.statusCode + ' when requesting ' + service + '. The url is ' + url); | ||
@@ -112,0 +122,0 @@ myError.body = _.get(resp, 'body') |
{ | ||
"name": "sparc-commons", | ||
"version": "0.2.25", | ||
"version": "0.2.26", | ||
"description": "Library with all small time common stuff used across the SPARC echosystem", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,2 +17,3 @@ { | ||
} | ||
} |
{ | ||
//TODO: hook this up in a http making library | ||
"resource": { | ||
"_DOC_": "The possible values for logging are 'ALWAYS', 'ON_ERROR', 'NEVER'", | ||
"test_resource": { | ||
"logging": "ALWAYS", | ||
"method": "get", | ||
@@ -6,0 +7,0 @@ "url": "http://bogus.com", |
50962
1248