Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/hooks/open-telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"current-version": "echo $npm_package_version"
},
"peerDependencies": {
"@openfeature/js-sdk": "^0.4.0"
"@openfeature/js-sdk": "~0.5.0"
},
"license": "Apache-2.0"
}
2 changes: 1 addition & 1 deletion libs/providers/flagd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"current-version": "echo $npm_package_version"
},
"peerDependencies": {
"@openfeature/js-sdk": "^0.4.0"
"@openfeature/js-sdk": "~0.5.0"
}
}
3 changes: 2 additions & 1 deletion libs/providers/flagd/src/lib/service/grpc/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as grpc from '@grpc/grpc-js';
import {
EvaluationContext,
FlagNotFoundError,
GeneralError,
JsonValue,
Logger,
ParseError,
Expand Down Expand Up @@ -138,7 +139,7 @@ export class GRPCService implements Service {
case Codes.Unavailable:
throw new FlagNotFoundError(err.message);
default:
throw err;
throw new GeneralError(err.message);
}
}
}
6 changes: 3 additions & 3 deletions libs/providers/go-feature-flag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "@openfeature/go-feature-flag-provider",
"version": "0.3.0",
"type": "commonjs",
"peerDependencies": {
"@openfeature/js-sdk": "^0.4.0"
},
"scripts": {
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi",
"current-version": "echo $npm_package_version"
},
"peerDependencies": {
"@openfeature/js-sdk": "~0.5.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*/
import {
ErrorCode,
FlagNotFoundError,
ResolutionDetails,
FlagNotFoundError, ResolutionDetails,
StandardResolutionReasons,
TypeMismatchError,
TypeMismatchError
} from '@openfeature/js-sdk';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
Expand Down Expand Up @@ -65,6 +64,40 @@ describe('GoFeatureFlagProvider', () => {
});
});

describe('error codes in HTTP response', () => {
it('SDK error codes should return correct code', async () => {
const flagName = 'random-other-flag';
const targetingKey = 'user-key';
const dns = `${endpoint}v1/feature/${flagName}/eval`;
axiosMock.onPost(dns).reply(200, {
value: true,
variationType: 'trueVariation',
errorCode: ErrorCode.PARSE_ERROR,
} as GoFeatureFlagProxyResponse<boolean>);
await goff
.resolveBooleanEvaluation(flagName, false, { targetingKey })
.then((result) => {
expect(result.errorCode).toEqual(ErrorCode.PARSE_ERROR)
})
});

it('unknown error codes should return GENERAL code', async () => {
const flagName = 'random-other-other-flag';
const targetingKey = 'user-key';
const dns = `${endpoint}v1/feature/${flagName}/eval`;
axiosMock.onPost(dns).reply(200, {
value: true,
variationType: 'trueVariation',
errorCode: 'NOT-AN-SDK-ERROR',
} as unknown as GoFeatureFlagProxyResponse<boolean>);
await goff
.resolveBooleanEvaluation(flagName, false, { targetingKey })
.then((result) => {
expect(result.errorCode).toEqual(ErrorCode.GENERAL)
})
});
});

it('should throw an error if we fail in other network errors case', async () => {
const flagName = 'random-flag';
const targetingKey = 'user-key';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ export class GoFeatureFlagProvider implements Provider {
const sdkResponse: ResolutionDetails<T> = {
value: apiResponseData.value,
variant: apiResponseData.variationType,
reason: apiResponseData.reason.toString(),
reason: apiResponseData.reason?.toString() || 'UNKNOWN'
};
if (apiResponseData.errorCode) {
sdkResponse.errorCode = apiResponseData.errorCode.toString();
if (Object.values(ErrorCode).includes(apiResponseData.errorCode as ErrorCode)) {
sdkResponse.errorCode = ErrorCode[apiResponseData.errorCode as ErrorCode];
} else if (apiResponseData.errorCode) {
sdkResponse.errorCode = ErrorCode.GENERAL;
}
return sdkResponse;
}
Expand Down
7 changes: 3 additions & 4 deletions libs/providers/go-feature-flag/src/lib/model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ErrorCode,
JSONValue,
StandardResolutionReasons,
EvaluationContextValue,
} from '@openfeature/js-sdk';

/**
Expand All @@ -13,7 +12,7 @@ export interface GoFeatureFlagUser {
key: string;
anonymous?: boolean;
custom?: {
[key: string]: JSONValue;
[key: string]: EvaluationContextValue;
};
}

Expand All @@ -37,7 +36,7 @@ export interface GoFeatureFlagProxyResponse<T> {
value: T;
variationType: string;
version?: string;
reason: StandardResolutionReasons | GOFeatureFlagResolutionReasons;
reason: string | GOFeatureFlagResolutionReasons;
errorCode?: ErrorCode | GOFeatureFlagErrorCode;
}

Expand Down
52 changes: 16 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"@nrwl/nx-cloud": "latest",
"@nrwl/web": "^14.2.4",
"@nrwl/workspace": "14.2.1",
"@openfeature/js-sdk": "~0.5.0",
"@types/jest": "27.4.1",
"@types/node": "16.11.7",
"@types/object-hash": "^2.2.1",
"@typescript-eslint/eslint-plugin": "~5.24.0",
"@typescript-eslint/parser": "~5.24.0",
"@openfeature/js-sdk": "^0.4.0",
"axios-mock-adapter": "^1.21.1",
"babel-preset-minify": "^0.5.2",
"eslint": "~8.15.0",
Expand Down