Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #53 from Financial-Times/add-logging-in-getLicence…
Browse files Browse the repository at this point in the history
…s-function

increase logs in getLicences function
  • Loading branch information
leggsimon authored Jun 20, 2018
2 parents b4597cc + d82ee42 commit 361e82f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/accessLicenceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ function getLicences (query) {
const operation = 'accessLicenceClient.getLicences';
log.debug({operation, query: JSON.stringify(query)});

if (query.adminuserid || query.linkid || query.linktype || query.status || query.userid) {
const queryString = helpers.createParams(query);
const url = `${config.API_GATEWAY_HOST}/licences${queryString}`;
return fetch(url, Object.assign({}, options))
.then(res => helpers.parseJsonRes(res, `${operation} ${queryString}`))
.then(res => {
log.debug({operation, queryString, res: 'success'});
return res.accessLicences;
});
if (!(query.adminuserid || query.linkid || query.linktype || query.status || query.userid)) {
const error = new Error('At least one of adminuserid | linkid | linktype | status | userid must be specified');
return Promise.reject(error);
}
return Promise.reject(Error('At least one of adminuserid | linkid | linktype | status | userid must be specified'));

const queryString = helpers.createParams(query);
const url = `${config.API_GATEWAY_HOST}/licences${queryString}`;

log.info({operation, msg: 'Requesting licences user administrates form Access Licence Service', url });

return fetch(url, Object.assign({}, options))
.then(res => {
log.info({ operation, msg: `Recieved status ${res.status} from Access Licence Service` });
const message = `${operation} ${queryString}`;
return helpers.parseJsonRes(res, message);
})
.then(res => {
log.info({ operation, queryString, status: res.status, res: JSON.stringify(res) });
return res.accessLicences;
});
}

/**
Expand Down

0 comments on commit 361e82f

Please sign in to comment.