Skip to content

Commit 2f66818

Browse files
authored
swap order of code blocks to prevent a null error when user is undefined (#574)
1 parent b620b93 commit 2f66818

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

backend/packages/Upgrade/src/api/services/ExperimentAssignmentService.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,8 @@ export class ExperimentAssignmentService {
398398
this.experimentUserService.getOriginalUserDoc(userId, logger)
399399
]);
400400

401-
const experimentUser: ExperimentUser = userDoc || {
402-
createdAt: experimentUserDoc.createdAt,
403-
id: experimentUserDoc.id,
404-
requestedUserId: userId,
405-
group: experimentUserDoc.group,
406-
workingGroup: experimentUserDoc.workingGroup
407-
};
408-
409401
// throw error if user not defined
410-
if (!experimentUser) {
402+
if (!experimentUserDoc || !experimentUserDoc.id) {
411403
logger.error({ message: `User not defined in getAllExperimentConditions: ${userId}` });
412404
let error = new Error(
413405
JSON.stringify({
@@ -420,6 +412,14 @@ export class ExperimentAssignmentService {
420412
throw error;
421413
}
422414

415+
const experimentUser: ExperimentUser = userDoc || {
416+
createdAt: experimentUserDoc.createdAt,
417+
id: experimentUserDoc.id,
418+
requestedUserId: userId,
419+
group: experimentUserDoc.group,
420+
workingGroup: experimentUserDoc.workingGroup
421+
};
422+
423423
// query all experiment and sub experiment
424424
// check if user or group is excluded
425425
let experiments: Experiment[] = [], userExcluded: string, groupExcluded: string[];

0 commit comments

Comments
 (0)