Skip to content

Commit bf5c1aa

Browse files
authored
Merge pull request #279 from skyflowapi/SK-2510-Fix-Node-SDK-issues
aadarsh-st/SK-2510-Fixed all the mentioned issue
2 parents f43033b + 4ecd39b commit bf5c1aa

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/error/messages/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const errorMessages = {
2424
INVALID_CREDENTIALS_FILE_PATH: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Expected file path to exists.`,
2525
INVALID_KEY: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid api key.`,
2626
INVALID_PARSED_CREDENTIALS_STRING: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid credentials string.`,
27-
INVALID_BEARER_TOKEN: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Specify a valid token.`,
27+
INVALID_BEARER_TOKEN: `${errorPrefix} Initialization failed. Invalid skyflow credentials. Bearer token is invalid or expired. Specify a valid token.`,
2828

2929
INVALID_FILE_PATH_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Expected file path to exists for %s1 with %s2 %s3.`,
3030
INVALID_KEY_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid api key for %s1 with %s2 %s3.`,
3131
INVALID_PARSED_CREDENTIALS_STRING_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid credentials string for %s1 with %s2 %s3.`,
32-
INVALID_BEARER_TOKEN_WITH_ID: `${errorPrefix} Initialization failed. Invalid credentials. Specify a valid token for %s1 with %s2 %s3.`,
32+
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.`,
3333

3434
EMPTY_CONNECTION_ID_VALIDATION: `${errorPrefix} Validation error. Invalid connection ID. Specify a valid connection Id.`,
3535
EMPTY_CONNECTION_ID: `${errorPrefix} Initialization failed. Invalid connection ID. Specify a valid connection Id.`,

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ export function fillUrlWithPathAndQueryParams(url: string,
451451
let filledUrl = url;
452452
if (pathParams) {
453453
Object.entries(pathParams).forEach(([key, value]) => {
454-
filledUrl = url.replace(`{${key}}`, String(value));
454+
filledUrl = filledUrl.replace(`{${key}}`, String(value));
455455
});
456-
}
456+
}
457457
if (queryParams) {
458458
filledUrl += '?';
459459
Object.entries(queryParams).forEach(([key, value]) => {

src/vault/controller/connections/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,38 @@ class ConnectionController {
6161
headers: { ...invokeRequest.headers, ...sdkHeaders },
6262
})
6363
.then(async (response) => {
64-
if(!response.ok){
65-
const errorBody = await response.json().catch(() => null);
64+
if (!response.ok) {
65+
let errorBody:unknown = null ;
6666

67-
const error = {
67+
try {
68+
errorBody = await response.json();
69+
} catch {
70+
try {
71+
const text = await response.text();
72+
errorBody = text ? { message: text } : null;
73+
} catch {
74+
response.body?.cancel().catch(() => { });
75+
}
76+
}
77+
78+
throw {
6879
body: errorBody,
6980
statusCode: response.status,
7081
message: response.statusText,
7182
headers: response.headers
7283
};
73-
throw error;
7484
}
85+
7586
const headers = response.headers;
76-
return response.json().then((body) => ({ headers, body }));
87+
const body = await response.json();
88+
return { headers, body };
7789
})
90+
7891
.then(({headers, body}) => {
7992
printLog(logs.infoLogs.INVOKE_CONNECTION_REQUEST_RESOLVED, MessageType.LOG, this.logLevel);
8093
const requestId = headers?.get(REQUEST.ID_KEY) || '';
8194
const invokeConnectionResponse = new InvokeConnectionResponse({
82-
data: body,
95+
data:body,
8396
metadata: { requestId },
8497
errors: null
8598
});

test/vault/utils/utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe('fillUrlWithPathAndQueryParams', () => {
163163
const url = '/api/resource/{category}/{id}';
164164
const pathParams = { category: 'books', id: '456' };
165165
const result = fillUrlWithPathAndQueryParams(url, pathParams);
166-
expect(result).toBe('/api/resource/{category}/456');
166+
expect(result).toBe('/api/resource/books/456');
167167
});
168168

169169
test('should handle query parameters with special characters', () => {

0 commit comments

Comments
 (0)