From 1149a20b89f81ce4873332034730b905f9086952 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 12 Aug 2020 19:11:06 +0200 Subject: [PATCH] Use Error instances for throw Former-commit-id: 36755e93616cd0cc9db32e0291c1824c825a44d9 --- .../clients/systeminformation-api.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ccm-core-apiclient/src/main/typescript/clients/systeminformation-api.ts b/ccm-core-apiclient/src/main/typescript/clients/systeminformation-api.ts index a99cf1699..0a297b112 100644 --- a/ccm-core-apiclient/src/main/typescript/clients/systeminformation-api.ts +++ b/ccm-core-apiclient/src/main/typescript/clients/systeminformation-api.ts @@ -1,6 +1,8 @@ import { ApiResponse, LibreCcmApiClient, + ApiError, + ApiClientError, } from "@libreccm/ccm-apiclient-commons"; import * as Constants from "../constants"; @@ -23,11 +25,22 @@ export class SystemInformationClient { if (response.ok) { return (await response.json()) as Record; } else { - throw `Failed get system information: - ${response.status} ${response.statusText}`; + throw new ApiError( + response.status, + response.statusText, + "get", + "Failed to get system information", + this.#SYSINFO_API_PREFIX + ); } } catch (err) { - throw `Failed to get system information: ${err}`; + if (err instanceof ApiError) { + throw err; + } else { + throw new ApiClientError( + `Failed to get system information: ${err}` + ); + } } } }