diff --git a/ccm-core-apiclient/src/main/typescript/clients/categorization-api.ts b/ccm-core-apiclient/src/main/typescript/clients/categorization-api.ts index b77515692..f0b010639 100644 --- a/ccm-core-apiclient/src/main/typescript/clients/categorization-api.ts +++ b/ccm-core-apiclient/src/main/typescript/clients/categorization-api.ts @@ -572,11 +572,12 @@ export class CategorizationApiClient { limit = 20, offset = 0 ): Promise> { + const url = `${this.#CATEGORIES_API_PREFIX}/$domain/${path}/@objects`; try { - const response: ApiResponse = await this.#apiClient.get( - `${this.#CATEGORIES_API_PREFIX}/$domain/${path}/@objects`, - { limit: limit.toString(), offset: offset.toString() } - ); + const response: ApiResponse = await this.#apiClient.get(url, { + limit: limit.toString(), + offset: offset.toString(), + }); if (response.ok) { const result: Record< @@ -598,12 +599,22 @@ export class CategorizationApiClient { offset: result.offset as number, }; } else { - throw `Failed to get objects in category ${path} of - domain ${domain}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "get", + `Failed to get objects in category ${path} of domain ${domain}`, + url + ); } } catch (err) { - throw `Failed to get objects in category ${path} of - domain ${domain}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to get objects in category ${path} of domain ${domain}: ${err}` + ); + } } } @@ -612,14 +623,12 @@ export class CategorizationApiClient { limit = 20, offset = 0 ): Promise> { + const url = `${this.#CATEGORIES_API_PREFIX}/ID-${categoryId}/@objects`; try { - const response: ApiResponse = await this.#apiClient.get( - `${this.#CATEGORIES_API_PREFIX}/ID-${categoryId}/@objects`, - { - limit: limit.toString(), - offset: offset.toString(), - } - ); + const response: ApiResponse = await this.#apiClient.get(url, { + limit: limit.toString(), + offset: offset.toString(), + }); if (response.ok) { const result: Record< @@ -641,12 +650,22 @@ export class CategorizationApiClient { offset: result.offset as number, }; } else { - throw `Failed to get objects in category with - ID ${categoryId}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "get", + `Failed to get objects in category with ID ${categoryId}`, + url + ); } } catch (err) { - throw `Failed to get objects in category with - Id ${categoryId}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to get objects in category with Id ${categoryId}: ${err}` + ); + } } } @@ -655,14 +674,12 @@ export class CategorizationApiClient { limit = 20, offset = 0 ): Promise> { + const url = `${this.#CATEGORIES_API_PREFIX}/UUID-${uuid}/@objects`; try { - const response: ApiResponse = await this.#apiClient.get( - `${this.#CATEGORIES_API_PREFIX}/UUID-${uuid}/@objects`, - { - limit: limit.toString(), - offset: offset.toString(), - } - ); + const response: ApiResponse = await this.#apiClient.get(url, { + limit: limit.toString(), + offset: offset.toString(), + }); if (response.ok) { const result: Record< @@ -684,12 +701,22 @@ export class CategorizationApiClient { offset: result.offset as number, }; } else { - throw `Failed to get objects in category with - UUID ${uuid}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "get", + `Failed to get objects in category with UUID ${uuid}`, + url + ); } } catch (err) { - throw `Failed to get objects in category with - UUId ${uuid}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to get objects in category with UUId ${uuid}: ${err}` + ); + } } } @@ -698,9 +725,10 @@ export class CategorizationApiClient { path: string, categorization: Categorization ): Promise { + const url = `${this.#CATEGORIES_API_PREFIX}/${domain}/${path}`; try { const response: ApiResponse = await this.#apiClient.post( - `${this.#CATEGORIES_API_PREFIX}/${domain}/${path}`, + url, JSON.stringify(categorization) ); @@ -708,12 +736,22 @@ export class CategorizationApiClient { const result: string = await response.text(); return result; } else { - throw `Failed to add object to category ${path} of - domain ${domain}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "post", + `Failed to add object to category ${path} of domain ${domain}`, + url + ); } } catch (err) { - throw `Failed to add object to category ${path} of - domain ${domain}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to add object to category ${path} of domain ${domain}: ${err}` + ); + } } } @@ -721,9 +759,10 @@ export class CategorizationApiClient { categoryId: number, categorization: Categorization ): Promise { + const url = `${this.#CATEGORIES_API_PREFIX}/ID-${categoryId}`; try { const response: ApiResponse = await this.#apiClient.post( - `${this.#CATEGORIES_API_PREFIX}/ID-${categoryId}`, + url, JSON.stringify(categorization) ); @@ -731,12 +770,22 @@ export class CategorizationApiClient { const result: string = await response.text(); return result; } else { - throw `Failed to add object to category with - ID ${categoryId}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "post", + `Failed to add object to category with ID ${categoryId}`, + url + ); } } catch (err) { - throw `Failed to add object to category with - ID ${categoryId}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to add object to category with ID ${categoryId}: ${err}` + ); + } } } @@ -744,9 +793,10 @@ export class CategorizationApiClient { uuid: string, categorization: Categorization ): Promise { + const url = `${this.#CATEGORIES_API_PREFIX}/UUID-${uuid}`; try { const response: ApiResponse = await this.#apiClient.post( - `${this.#CATEGORIES_API_PREFIX}/UUID-${uuid}`, + url, JSON.stringify(categorization) ); @@ -754,12 +804,22 @@ export class CategorizationApiClient { const result: string = await response.text(); return result; } else { - throw `Failed to add object to category with - UUID ${uuid}: ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "post", + `Failed to add object to category with UUID ${uuid}`, + url + ); } } catch (err) { - throw `Failed to add object to category with - UUID ${uuid}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to add object to category with UUID ${uuid}: ${err}` + ); + } } } @@ -768,23 +828,30 @@ export class CategorizationApiClient { path: string, objectIdentifier: string ): Promise { + const url = `${ + this.#CATEGORIES_API_PREFIX + }/${domain}/${path}/@objects/${objectIdentifier}`; try { - const response: ApiResponse = await this.#apiClient.delete( - `${ - this.#CATEGORIES_API_PREFIX - }/${domain}/${path}/@objects/${objectIdentifier}` - ); + const response: ApiResponse = await this.#apiClient.delete(url); if (response.ok) { return; } else { - throw `Failed to remove object ${objectIdentifier} from - category ${path} of domain ${domain}: - ${response.status} ${response.statusText}.`; + throw new ApiError( + response.status, + response.statusText, + "delete", + `Failed to remove object ${objectIdentifier} from category ${path} of domain ${domain}`, + url + ); } } catch (err) { - throw `Failed to remove object ${objectIdentifier} from - category ${path} of domain ${domain}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError(`Failed to remove object ${objectIdentifier} from + category ${path} of domain ${domain}: ${err}`); + } } } @@ -792,23 +859,31 @@ export class CategorizationApiClient { categoryId: number, objectIdentifier: string ): Promise { + const url = `${ + this.#CATEGORIES_API_PREFIX + }/ID-${categoryId}/@objects/${objectIdentifier}`; try { - const response: ApiResponse = await this.#apiClient.delete( - `${ - this.#CATEGORIES_API_PREFIX - }/ID-${categoryId}/@objects/${objectIdentifier}` - ); + const response: ApiResponse = await this.#apiClient.delete(url); if (response.ok) { return; } else { - throw `Failed to remove object ${objectIdentifier} from - category with ID ${categoryId}: - ${response.status} ${response.statusText}.`; + throw new ApiError( + response.status, + response.statusText, + "delete", + `Failed to remove object ${objectIdentifier} from category with ID ${categoryId}`, + url + ); } } catch (err) { - throw `Failed to remove object ${objectIdentifier} from - category with ID ${categoryId}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to remove object ${objectIdentifier} from category with ID ${categoryId}: ${err}` + ); + } } } @@ -816,23 +891,31 @@ export class CategorizationApiClient { uuid: string, objectIdentifier: string ): Promise { + const url = `${ + this.#CATEGORIES_API_PREFIX + }/UUID-${uuid}/@objects/${objectIdentifier}`; try { - const response: ApiResponse = await this.#apiClient.delete( - `${ - this.#CATEGORIES_API_PREFIX - }/UUID-${uuid}/@objects/${objectIdentifier}` - ); + const response: ApiResponse = await this.#apiClient.delete(url); if (response.ok) { return; } else { - throw `Failed to remove object ${objectIdentifier} from - category with UUID ${uuid}: - ${response.status} ${response.statusText}.`; + throw new ApiError( + response.status, + response.statusText, + "delete", + `Failed to remove object ${objectIdentifier} from category with UUID ${uuid}`, + url + ); } } catch (err) { - throw `Failed to remove object ${objectIdentifier} from - category with UUID ${uuid}: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to remove object ${objectIdentifier} from category with UUID ${uuid}: ${err}` + ); + } } } }