Skip to content
Merged
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
25 changes: 19 additions & 6 deletions src/vault/controller/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,38 @@ class ConnectionController {
headers: { ...invokeRequest.headers, ...sdkHeaders },
})
.then(async (response) => {
if(!response.ok){
const errorBody = await response.json().catch(() => null);
if (!response.ok) {
let errorBody:unknown = null ;

const error = {
try {
errorBody = await response.json();
} catch {
try {
const text = await response.text();
errorBody = text ? { message: text } : null;
} catch {
response.body?.cancel().catch(() => { });
}
}

throw {
body: errorBody,
statusCode: response.status,
message: response.statusText,
headers: response.headers
};
throw error;
}

const headers = response.headers;
return response.json().then((body) => ({ headers, body }));
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 invokeConnectionResponse = new InvokeConnectionResponse({
data: body,
data:body,
metadata: { requestId },
errors: null
});
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