js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

[FEATURE] ResolutionDetails improved typing for error cases.

Open toddbaert opened this issue 3 years ago • 2 comments

Requirements

Improve typings of EvaluationDetails and ResolutionDetails by forcing the addition of errorCode if reason = ERROR.

toddbaert avatar Sep 29 '22 15:09 toddbaert

shouldn't this be the other way around? if error code is error, then you need a reason for the error code?

mowies avatar Mar 27 '23 07:03 mowies

@mowies I see why you'd think that, but in the semantics of the SDK, the REASON field is not a REASON for an error. It's the reason that the resolution proceeded the way it did.

For example, if a flag evaluated to true because it's defined statically as true, than the provider can set the REASON to STATIC. If the flag evaluated to true because a certain targeting rule was hit, that would be TARGETING_MATCH. See the table from the spec here. REASONs are something like HTTP status codes, which can indicate both success and error, but their main purpose is to communicate the why. Similarly to HTTP status code, they can be extended, but a limited list of pre-defined reasons is shipped with SDKs.

This issue is to force the population of errorCode if Reason === Error, which is something the spec recommends: https://docs.openfeature.dev/docs/specification/sections/flag-evaluation/#requirement-148

toddbaert avatar Mar 28 '23 17:03 toddbaert