Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit b075b25

Browse files
#12 - Improve error messages
1 parent 60eb61a commit b075b25

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/services/ProcessorService.js

+24
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,17 @@ async function createUserSkill (userId, skillProviderName, skillName, certifierI
144144
return
145145
}
146146
const skillProvider = await helper.getUbahnSingleRecord('/skillsProviders', { name: skillProviderName })
147+
148+
if (!skillProvider) {
149+
throw Error(`Cannot find skill provider with name ${skillProviderName}`)
150+
}
151+
147152
const skill = await helper.getUbahnSingleRecord('/skills', { skillProviderId: skillProvider.id, name: skillName })
148153

154+
if (!skill) {
155+
throw Error(`Cannot find skill with name ${skillName} under skill provider ${skillProviderName}`)
156+
}
157+
149158
// Does the skill already exist on the user?
150159
const existingSkill = await helper.getUbahnSingleRecord(`/users/${userId}/skills/${skill.id}`, {}, true)
151160

@@ -174,6 +183,11 @@ async function createAchievement (userId, providerName, certifierId, certifiedDa
174183
return
175184
}
176185
const achievementsProvider = await helper.getUbahnSingleRecord('/achievementsProviders', { name: providerName })
186+
187+
if (!achievementsProvider) {
188+
throw Error(`Cannot find achievement provider with name ${providerName}`)
189+
}
190+
177191
const existingAchievement = await helper.getUbahnSingleRecord(`/users/${userId}/achievements/${achievementsProvider.id}`, {}, true)
178192

179193
if (!existingAchievement || !existingAchievement.id) {
@@ -201,7 +215,17 @@ async function createUserAttributes (userId, record) {
201215
return
202216
}
203217
const attributeGroup = await helper.getUbahnSingleRecord('/attributeGroups', { name: record[`attributeGroupName${i}`] })
218+
219+
if (!attributeGroup) {
220+
throw Error(`Cannot find attribute group with name ${record[`attributeGroupName${i}`]}`)
221+
}
222+
204223
const attribute = await helper.getUbahnSingleRecord('/attributes', { attributeGroupId: attributeGroup.id, name: record[`attributeName${i}`] })
224+
225+
if (!attribute) {
226+
throw Error(`Cannot find attribute with name ${record[`attributeName${i}`]} under attribute group wth name ${record[`attributeGroupName${i}`]}`)
227+
}
228+
205229
const value = _.toString(record[`attributeValue${i}`])
206230
const existingAttribute = await helper.getUbahnSingleRecord(`/users/${userId}/attributes/${attribute.id}`, {}, true)
207231

0 commit comments

Comments
 (0)