Skip to content

Commit a420728

Browse files
fixes
1 parent 4b0f48c commit a420728

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

app.js

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ app.use((err, req, res, next) => {
9292
}
9393
}
9494

95+
if (!_.isUndefined(err.metadata)) {
96+
errorResponse.metadata = err.metadata
97+
}
98+
9599
res.status(status).json(errorResponse)
96100
})
97101

src/common/helper.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -427,26 +427,23 @@ function partialMatch (filter, value) {
427427
* Check if the user has agreed to all challenge terms
428428
* @param {Number} userId the user ID
429429
* @param {Array<String>} terms an array of term UUIDs to check
430-
* @param {String} roleId the role ID
431430
*/
432-
async function checkAgreedTerms (userId, terms, roleId) {
431+
async function checkAgreedTerms (userId, terms) {
433432
const unAgreedTerms = []
434-
const unAgreedTermIds = []
433+
const missingTerms = []
435434
for (const term of terms) {
436435
const res = await getRequest(`${config.TERMS_API_URL}/${term.id}`, { userId })
437436
if (!_.get(res, 'body.agreed', false)) {
438437
unAgreedTerms.push(_.get(res, 'body.title', term))
439-
unAgreedTermIds.push({
438+
missingTerms.push({
440439
termId: term.id,
441-
roleId
440+
roleId: term.roleId
442441
})
443442
}
444443
}
445444

446445
if (unAgreedTerms.length > 0) {
447-
throw new errors.ForbiddenError(`The user has not yet agreed to the following terms: [${unAgreedTerms.join(', ')}]`, null, {
448-
missingTerms: unAgreedTermIds
449-
})
446+
throw new errors.ForbiddenError(`The user has not yet agreed to the following terms: [${unAgreedTerms.join(', ')}]`, null, { missingTerms })
450447
}
451448
}
452449

src/services/ResourceService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async function init (currentUser, challengeId, resource, isCreated) {
252252
let resources
253253
// Verify the member has agreed to the challenge terms
254254
if (isCreated) {
255-
await helper.checkAgreedTerms(memberId, _.filter(_.get(challenge, 'terms', []), t => t.roleId === resourceRole.id), resourceRole.id)
255+
await helper.checkAgreedTerms(memberId, _.filter(_.get(challenge, 'terms', []), t => t.roleId === resourceRole.id))
256256
}
257257
if (!currentUser.isMachine && !helper.hasAdminRole(currentUser)) {
258258
// Check if user has agreed to the challenge terms

0 commit comments

Comments
 (0)