Skip to content

Commit

Permalink
- Added check for the fetch() api in case its not available
Browse files Browse the repository at this point in the history
- More robust Query.toString() to handle cases where an empty query might be passed in as an argument
  • Loading branch information
DavidArayan committed Dec 11, 2023
1 parent e64cb9f commit 7215778
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sdk-core/src/core/query/core-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ export abstract class CoreQuery<T extends CoreObject<U>, U extends CoreObjectAtt
let url: string = '';

queries.forEach((query: Query) => {
url += `${query.toString()}&`;
const queryString: string = query.toString();

if (queryString !== '') {
url += `${queryString}&`;
}
});

// remove the last & keyword
Expand All @@ -171,6 +175,17 @@ export abstract class CoreQuery<T extends CoreObject<U>, U extends CoreObjectAtt
public static async fetch<T extends CoreObject<CoreObjectAttributes>>(service: Service, instance: T, encodedURL: string, type: QueryFetchType, abort?: AbortSignal): Promise<Array<T>> {
const results: Array<T> = new Array<T>();

if (!fetch) {
CoreError.init({
error: {
title: 'Runtime Error',
text: `native fetch api not available, uprade your ${Util.isNode() ? 'NodeJS' : 'Browser'} environment`
}
}).handle(service);

return results;
}

const headers: HeadersInit = {
'Content-Type': 'application/json',
'Accept': 'application/json'
Expand Down

0 comments on commit 7215778

Please sign in to comment.