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:
parent
004ad083dc
commit
39ae4fe113
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue