feat: improve error log and add flag disabled handling for ofrep (#1306)

## This PR

- Handle `FlagDisabledErrorCode` and include a specific error message
along with general error code
- Improve error message for targeting rule validation failure

---------

Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
This commit is contained in:
Kavindu Dodanduwa 2024-05-10 07:34:58 -07:00 committed by GitHub
parent 004ad083dc
commit 39ae4fe113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -376,7 +376,7 @@ func (je *Resolver) evaluateVariant(ctx context.Context, reqID string, flagKey s
// evaluate JsonLogic rules to determine the variant
err = jsonlogic.Apply(bytes.NewReader(targetingBytes), bytes.NewReader(b), &result)
if err != nil {
je.Logger.ErrorWithID(reqID, fmt.Sprintf("error applying rules: %s", err))
je.Logger.ErrorWithID(reqID, fmt.Sprintf("error applying targeting rules: %s", err))
return "", flag.Variants, model.ErrorReason, metadata, errors.New(model.ParseErrorCode)
}

View File

@ -92,6 +92,10 @@ func EvaluationErrorResponseFrom(result evaluator.AnyValue) (int, EvaluationErro
status = 404
payload.ErrorCode = model.FlagNotFoundErrorCode
payload.ErrorDetails = fmt.Sprintf("flag `%s` does not exist", result.FlagKey)
case model.FlagDisabledErrorCode:
status = 404
payload.ErrorCode = model.FlagNotFoundErrorCode
payload.ErrorDetails = fmt.Sprintf("flag `%s` is disabled", result.FlagKey)
case model.ParseErrorCode:
payload.ErrorCode = model.ParseErrorCode
payload.ErrorDetails = fmt.Sprintf("error parsing the flag `%s`", result.FlagKey)

View File

@ -89,8 +89,8 @@ func TestErrorStatus(t *testing.T) {
{
name: "flag disabled",
modelError: model.FlagDisabledErrorCode,
expectedStatus: 400,
expectedCode: model.GeneralErrorCode,
expectedStatus: 404,
expectedCode: model.FlagNotFoundErrorCode,
},
{
name: "general error",