From 1c0ca0549d75f2e3013837fcab51de3cd693b6ca Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Tue, 7 Mar 2023 16:12:33 -0500 Subject: [PATCH 1/4] chore: unskip failing tests --- harness/features/allFeatures.cloud.test.ts | 3 +-- harness/features/initialize.local.test.ts | 7 +++---- harness/features/variable.cloud.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/harness/features/allFeatures.cloud.test.ts b/harness/features/allFeatures.cloud.test.ts index 40b1bf74..35aba2f0 100644 --- a/harness/features/allFeatures.cloud.test.ts +++ b/harness/features/allFeatures.cloud.test.ts @@ -70,8 +70,7 @@ describe('allFeatures Tests - Cloud', () => { }) }) - // TODO DVC-5954 investigate why these were failing on the SDKs - it.skip('should throw if features request fails on invalid sdk key', async () => { + it('should throw if features request fails on invalid sdk key', async () => { scope .post(`/client/${testClient.clientId}/v1/features`) .reply(401, { message: 'Invalid sdk key' }) diff --git a/harness/features/initialize.local.test.ts b/harness/features/initialize.local.test.ts index 4b63f969..ffcc11a5 100644 --- a/harness/features/initialize.local.test.ts +++ b/harness/features/initialize.local.test.ts @@ -68,8 +68,7 @@ describe('Initialize Tests - Local', () => { await testClient.createClient(true, { configPollingIntervalMS: 10000 }) }) - // TODO DVC-6016 investigate why these were failing on the nodeJS SDK - it.skip('stops the polling interval when the sdk key is invalid and cdn responds 403,' + + it('stops the polling interval when the sdk key is invalid and cdn responds 403,' + ' throws error', async () => { const testClient = new LocalTestClient(name) @@ -158,7 +157,7 @@ describe('Initialize Tests - Local', () => { scope .get(`/client/${testClient.clientId}/config/v1/server/${testClient.sdkKey}.json`) - .reply(200, "I'm not JSON!") + .reply(200, 'I\'m not JSON!') await testClient.createClient(true, { configPollingIntervalMS: 1000 }) @@ -180,7 +179,7 @@ describe('Initialize Tests - Local', () => { scope .get(`/client/${testClient.clientId}/config/v1/server/${testClient.sdkKey}.json`) - .reply(200, "{\"snatch_movie_quote\": \"d'ya like dags?\"}") + .reply(200, '{"snatch_movie_quote": "d\'ya like dags?"}') await testClient.createClient(true, { configPollingIntervalMS: 1000 }) diff --git a/harness/features/variable.cloud.test.ts b/harness/features/variable.cloud.test.ts index b276ae57..5d648831 100644 --- a/harness/features/variable.cloud.test.ts +++ b/harness/features/variable.cloud.test.ts @@ -48,8 +48,8 @@ describe('Variable Tests - Cloud', () => { // from the proxy server expectErrorMessageToBe(error.asyncError, 'Missing parameter: key') }) - // TODO DVC-5954 investigate why these were failing on the SDKs - it.skip('will throw error if variable called with invalid sdk key', async () => { + + it('will throw error if variable called with invalid sdk key', async () => { scope .post(`/client/${testClient.clientId}/v1/variable/var_key`) .reply(401, { message: 'Invalid sdk key' }) From 9b5bf1bfb93a5a9d74f6bfba18bb2d128fd970f0 Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Tue, 7 Mar 2023 16:59:50 -0500 Subject: [PATCH 2/4] fix: use async error instead of exception to check 403 from onInitialized --- harness/features/initialize.local.test.ts | 4 ++-- harness/features/variable.cloud.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/harness/features/initialize.local.test.ts b/harness/features/initialize.local.test.ts index ffcc11a5..3addc793 100644 --- a/harness/features/initialize.local.test.ts +++ b/harness/features/initialize.local.test.ts @@ -78,10 +78,10 @@ describe('Initialize Tests - Local', () => { const response = await testClient.createClient(true, { configPollingIntervalMS: 1000 }, testClient.sdkKey, true) - const { exception } = await response.json() + const { asyncError } = await response.json() expectErrorMessageToBe( - exception, + asyncError, 'Invalid environment key provided. Please call initialize with a valid server environment key' ) diff --git a/harness/features/variable.cloud.test.ts b/harness/features/variable.cloud.test.ts index 5d648831..df0ad625 100644 --- a/harness/features/variable.cloud.test.ts +++ b/harness/features/variable.cloud.test.ts @@ -48,7 +48,7 @@ describe('Variable Tests - Cloud', () => { // from the proxy server expectErrorMessageToBe(error.asyncError, 'Missing parameter: key') }) - + it('will throw error if variable called with invalid sdk key', async () => { scope .post(`/client/${testClient.clientId}/v1/variable/var_key`) From 16b4d348518f7e1bd1cee42beef91815088138f2 Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Wed, 8 Mar 2023 10:24:57 -0500 Subject: [PATCH 3/4] fix: catch dotnet initialized wait throws --- harness/features/initialize.local.test.ts | 1 - proxies/dotnet/Controllers/Client.cs | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/harness/features/initialize.local.test.ts b/harness/features/initialize.local.test.ts index 3addc793..b8efa64b 100644 --- a/harness/features/initialize.local.test.ts +++ b/harness/features/initialize.local.test.ts @@ -84,7 +84,6 @@ describe('Initialize Tests - Local', () => { asyncError, 'Invalid environment key provided. Please call initialize with a valid server environment key' ) - }) it('fetches config again after 3 seconds when config polling interval is overriden', async () => { diff --git a/proxies/dotnet/Controllers/Client.cs b/proxies/dotnet/Controllers/Client.cs index 8c0eaff3..ec779d45 100644 --- a/proxies/dotnet/Controllers/Client.cs +++ b/proxies/dotnet/Controllers/Client.cs @@ -127,10 +127,15 @@ public async Task Post(ClientRequestBody ClientBody) .SetLogger(LoggerFactory.Create(builder => builder.AddConsole())) .Build(); + try { await task; if (eventArgs != null && !eventArgs.Success) { throw eventArgs.Errors[0]; } + } catch (Exception e) { + Response.StatusCode = 200; + return new { asyncError = e.Message }; + } } else { DataStore.LocalClients[ClientBody.ClientId] = new DVCLocalClientBuilder() .SetEnvironmentKey(ClientBody.SdkKey) From 954ff61e56faf410e3c05c5ce44bee5a357046ee Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Wed, 8 Mar 2023 11:48:40 -0500 Subject: [PATCH 4/4] fix: make exception into asyncError if WaitForInitialization is passed true --- harness/features/variable.cloud.test.ts | 3 ++- proxies/go/handler_client.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/harness/features/variable.cloud.test.ts b/harness/features/variable.cloud.test.ts index df0ad625..6b51e421 100644 --- a/harness/features/variable.cloud.test.ts +++ b/harness/features/variable.cloud.test.ts @@ -49,7 +49,8 @@ describe('Variable Tests - Cloud', () => { expectErrorMessageToBe(error.asyncError, 'Missing parameter: key') }) - it('will throw error if variable called with invalid sdk key', async () => { + // TODO DVC-5954 investigate why these were failing on the SDKs + it.skip('will throw error if variable called with invalid sdk key', async () => { scope .post(`/client/${testClient.clientId}/v1/variable/var_key`) .reply(401, { message: 'Invalid sdk key' }) diff --git a/proxies/go/handler_client.go b/proxies/go/handler_client.go index 6426760a..e26366ce 100644 --- a/proxies/go/handler_client.go +++ b/proxies/go/handler_client.go @@ -62,7 +62,11 @@ func clientHandler(w http.ResponseWriter, r *http.Request) { client, err := devcycle.NewDVCClient(reqBody.SdkKey, &options) if err != nil { - res.Exception = err.Error() + if reqBody.WaitForInitialization { + res.AsyncError = err.Error() + } else { + res.Exception = err.Error() + } w.WriteHeader(http.StatusOK) } else { res.Message = "success"