From 29fa82163d96ecc2611376a4016f3b55aa617319 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Wed, 28 Jan 2026 15:43:04 +0530 Subject: [PATCH 1/3] aadarsh-st/SK-2510-Fixed all the mentioned issue --- src/error/messages/index.ts | 4 ++-- src/utils/index.ts | 4 ++-- src/vault/controller/connections/index.ts | 17 ++++++++++++++++- test/vault/utils/utils.test.js | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index ca50746f..4a2f54cf 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -24,12 +24,12 @@ const errorMessages = { INVALID_CREDENTIALS_FILE_PATH: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Expected file path to exists.`, INVALID_KEY: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid api key.`, INVALID_PARSED_CREDENTIALS_STRING: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid credentials string.`, - INVALID_BEARER_TOKEN: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid token.`, + INVALID_BEARER_TOKEN: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Bearer token is invalid or expired. Specify a valid token.`, INVALID_FILE_PATH_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Expected file path to exists for %s1 with %s2 %s3.`, INVALID_KEY_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid api key for %s1 with %s2 %s3.`, INVALID_PARSED_CREDENTIALS_STRING_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid credentials string for %s1 with %s2 %s3.`, - INVALID_BEARER_TOKEN_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid token for %s1 with %s2 %s3.`, + INVALID_BEARER_TOKEN_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Bearer token is invalid or expired. Specify a valid token for %s1 with %s2 %s3.`, EMPTY_CONNECTION_ID_VALIDATION: `${errorPrefix} Validation error. Invalid connection ID. Specify a valid connection Id.`, EMPTY_CONNECTION_ID: `${errorPrefix} Initialization failed. Invalid connection ID. Specify a valid connection Id.`, diff --git a/src/utils/index.ts b/src/utils/index.ts index 856359e3..f00abcee 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -365,9 +365,9 @@ export function fillUrlWithPathAndQueryParams(url: string, let filledUrl = url; if (pathParams) { Object.entries(pathParams).forEach(([key, value]) => { - filledUrl = url.replace(`{${key}}`, String(value)); + filledUrl = filledUrl.replace(`{${key}}`, String(value)); }); - } + } if (queryParams) { filledUrl += '?'; Object.entries(queryParams).forEach(([key, value]) => { diff --git a/src/vault/controller/connections/index.ts b/src/vault/controller/connections/index.ts index c18abe22..30ef824f 100644 --- a/src/vault/controller/connections/index.ts +++ b/src/vault/controller/connections/index.ts @@ -62,7 +62,21 @@ class ConnectionController { }) .then(async (response) => { if(!response.ok){ - const errorBody = await response.json().catch(() => null); + let errorBody: any = null; + try { + errorBody = await response.json(); + } catch (jsonError) { + // If JSON parsing fails, consume as text to close connection + try { + const text = await response.text(); + errorBody = text ? { message: text } : null; + } catch (textError) { + // If text consumption also fails, ensure body is consumed + if (response.body) { + await response.body.cancel().catch(() => {}); + } + } + } const error = { body: errorBody, @@ -73,6 +87,7 @@ class ConnectionController { throw error; } const headers = response.headers; + // Consume response body - this will close the connection return response.json().then((body) => ({ headers, body })); }) .then(({headers, body}) => { diff --git a/test/vault/utils/utils.test.js b/test/vault/utils/utils.test.js index ffea9c3d..625de549 100644 --- a/test/vault/utils/utils.test.js +++ b/test/vault/utils/utils.test.js @@ -162,7 +162,7 @@ describe('fillUrlWithPathAndQueryParams', () => { const url = '/api/resource/{category}/{id}'; const pathParams = { category: 'books', id: '456' }; const result = fillUrlWithPathAndQueryParams(url, pathParams); - expect(result).toBe('/api/resource/{category}/456'); + expect(result).toBe('/api/resource/books/456'); }); test('should handle query parameters with special characters', () => { From 4614faa270e6b50808bc00a621c4238bbf5a5bc1 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Thu, 29 Jan 2026 13:26:03 +0530 Subject: [PATCH 2/3] aadarsh-st/SK-2510-Fixed comment by copilot --- src/vault/controller/connections/index.ts | 39 ++++++++++------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/vault/controller/connections/index.ts b/src/vault/controller/connections/index.ts index 30ef824f..e8451e37 100644 --- a/src/vault/controller/connections/index.ts +++ b/src/vault/controller/connections/index.ts @@ -61,40 +61,33 @@ class ConnectionController { headers: { ...invokeRequest.headers, ...sdkHeaders }, }) .then(async (response) => { - if(!response.ok){ - let errorBody: any = null; + const text = await response.text().catch(() => ""); + let body: unknown = null; + if (text) { try { - errorBody = await response.json(); - } catch (jsonError) { - // If JSON parsing fails, consume as text to close connection - try { - const text = await response.text(); - errorBody = text ? { message: text } : null; - } catch (textError) { - // If text consumption also fails, ensure body is consumed - if (response.body) { - await response.body.cancel().catch(() => {}); - } - } + body = JSON.parse(text); + } catch { + body = text; } - - const error = { - body: errorBody, + } + if (!response.ok) { + throw { + body, statusCode: response.status, - message: response.statusText, headers: response.headers }; - throw error; } - const headers = response.headers; - // Consume response body - this will close the connection - return response.json().then((body) => ({ headers, body })); + return { + headers: response.headers, + body + }; }) .then(({headers, body}) => { printLog(logs.infoLogs.INVOKE_CONNECTION_REQUEST_RESOLVED, MessageType.LOG, this.logLevel); const requestId = headers?.get(REQUEST_ID_KEY) || ''; + const data = typeof body === 'object' && body !== null ? body : {}; const invokeConnectionResponse = new InvokeConnectionResponse({ - data: body, + data, metadata: { requestId }, errors: null }); From 4ecd39ba110e7fe46c1a15c49e0595412053e349 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Thu, 29 Jan 2026 13:52:35 +0530 Subject: [PATCH 3/3] aadarsh-st/SK-2510- Fixed copilot comments --- src/vault/controller/connections/index.ts | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/vault/controller/connections/index.ts b/src/vault/controller/connections/index.ts index e8451e37..57edeb31 100644 --- a/src/vault/controller/connections/index.ts +++ b/src/vault/controller/connections/index.ts @@ -61,33 +61,38 @@ class ConnectionController { headers: { ...invokeRequest.headers, ...sdkHeaders }, }) .then(async (response) => { - const text = await response.text().catch(() => ""); - let body: unknown = null; - if (text) { + if (!response.ok) { + let errorBody:unknown = null ; + try { - body = JSON.parse(text); + errorBody = await response.json(); } catch { - body = text; + try { + const text = await response.text(); + errorBody = text ? { message: text } : null; + } catch { + response.body?.cancel().catch(() => { }); + } } - } - if (!response.ok) { + throw { - body, + body: errorBody, statusCode: response.status, + message: response.statusText, headers: response.headers }; } - return { - headers: response.headers, - body - }; + + const headers = response.headers; + const body = await response.json(); + return { headers, body }; }) + .then(({headers, body}) => { printLog(logs.infoLogs.INVOKE_CONNECTION_REQUEST_RESOLVED, MessageType.LOG, this.logLevel); const requestId = headers?.get(REQUEST_ID_KEY) || ''; - const data = typeof body === 'object' && body !== null ? body : {}; const invokeConnectionResponse = new InvokeConnectionResponse({ - data, + data:body, metadata: { requestId }, errors: null });