Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Improve 'Key Not Found' Error Messages #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LY Corporation
* Copyright 2025 LY Corporation
*
* LY Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -176,7 +176,7 @@ public Optional<Map<String, Object>> getFlagrVariantAttachment(EvaluationContext
private Optional<EvaluationResult> getEvaluationResult(EvaluationContext evaluationContext) {
try {
EvaluationResult evaluationResult = openFlagrApiClient.postEvaluation(evaluationContext);
validateReturnData(evaluationResult);
validateReturnData(evaluationContext, evaluationResult);
return Optional.ofNullable(evaluationResult);
} catch (OpenFlagrException e) {
log.error(e.getMessage());
Expand All @@ -193,12 +193,16 @@ private Optional<EvaluationResult> getEvaluationResult(EvaluationContext evaluat
}
}

private void validateReturnData(EvaluationResult evaluationResult) {
private void validateReturnData(EvaluationContext evaluationContext, EvaluationResult evaluationResult) {
if (evaluationResult.getFlagId() == null) {
throw new OpenFlagrNoFlagKeyException("Flag key not found. Please check UI panel.");
throw new OpenFlagrNoFlagKeyException(
String.format("The flag with key %s was not found. Please verify the flag key in the UI panel.",
evaluationContext.getFlagKey()));
}
if (evaluationResult.getVariantKey() == null) {
throw new OpenFlagrNoVariantException("No variant key found. Check rollout and distribution on UI panel.");
throw new OpenFlagrNoVariantException(
String.format("No variant key was found for flag key %s. Please check the rollout and distribution settings in the UI panel.",
evaluationContext.getFlagKey()));
}
}

Expand Down