Skip to content

Commit e627de9

Browse files
author
Sachin Maheshwari
committed
fixing public challenge api is not accessable issue.
1 parent 899da23 commit e627de9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ workflows:
102102
context : org-global
103103
filters:
104104
branches:
105-
only: [dev, 'bug/rate-limit']
105+
only: [dev, 'bug/community-notification']
106106
- "build-prod":
107107
context : org-global
108108
filters:

src/common/tcApiHelper.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function* getUsersByHandles(handles) {
8484
return [];
8585
}
8686
// use 'OR' to link the handle matches
87-
const query = _.map(handles, (h) => 'handle:"' + h.trim().replace('"', '\\"') + '"').join(' OR ');
87+
const query = _.map(handles, (h) => 'handle:"' + h.trim().replace('"', '\\"') + '"').join(' OR ');
8888
return yield searchUsersByQuery(query);
8989
}
9090

@@ -188,10 +188,20 @@ function* notifyUserViaEmail(user, message) {
188188
* @returns {Object} the challenge details
189189
*/
190190
function* getChallenge(challengeId) {
191-
// this is public API, M2M token is not needed
191+
const token = yield getM2MToken();
192+
// this is public API, but some challege is not accessable so using m2m token
192193
const url = `${config.TC_API_V4_BASE_URL}/challenges/${challengeId}`;
193194
logger.info(`calling public challenge api ${url}`);
194-
const res = yield request.get(url);
195+
const res = yield request
196+
.get(url)
197+
.set('Authorization', `Bearer ${token}`)
198+
.catch((err) => {
199+
const errorDetails = _.get(err, 'message');
200+
throw new Error(
201+
`Error in call public challenge api by id ${challengeId}` +
202+
(errorDetails ? ' Server response: ' + errorDetails : '')
203+
);
204+
});
195205
if (!_.get(res, 'body.result.success')) {
196206
throw new Error(`Failed to get challenge by id ${challengeId}`);
197207
}

0 commit comments

Comments
 (0)