Fix/issue-575: Handling no experimentId in mark api call#584
Conversation
| if (experimentDecisionPoint.length && experimentId !== '') { | ||
| let selectedExperimentDP = experimentDecisionPoint.filter( dp => dp.experiment.id === experimentId); |
There was a problem hiding this comment.
Just wondering if it's a better solution than let selectedExperimentDP = experimentDecisionPoint.filter( dp => dp.experiment.id === experimentId || experimentId === ''); which was what I did to not see the error.
There was a problem hiding this comment.
Both will give same result, but in your case it will check again for the dp which already we can filter out before as I have done and we just return the monitored dp.
|
If this is really all that's needed, then the tertiary condition to set the empty string really isn't necessary, we can simplify a little more: if (!experimentId) {
if (filteredExperiments.length > 1) {
const random = seedrandom(userId)();
experimentId = filteredExperiments[Math.floor(random * experiments.length)].id;
} else {
experimentId = filteredExperiments[0]?.id; // <--- no need for extra conditional here, let it be undefined, no need for empty string
}
}and then you can do this so that it's not just an empty string it's checking, it's checking all falsey values that would potentially get the same runtime error:
which also catches any weird edge-case where |
Okay, I will update the PR. Thanks :) |
* handling no experimentId in mark api call * updated the optional experimentId in mark
No description provided.