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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/error/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
17 changes: 16 additions & 1 deletion src/vault/controller/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}) => {
Expand Down
2 changes: 1 addition & 1 deletion test/vault/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading