parent
259aacca67
commit
2f53cb4b67
|
|
@ -22,7 +22,9 @@ export { LibreCcmApiClient, ApiResponse, ApiError, buildUrl };
|
||||||
*/
|
*/
|
||||||
export function buildEmbeddedApiClient(): LibreCcmApiClient {
|
export function buildEmbeddedApiClient(): LibreCcmApiClient {
|
||||||
if (!isFetchAvailable()) {
|
if (!isFetchAvailable()) {
|
||||||
throw "Fetch API is not available. Please use buildIsomorpicApiClient.";
|
throw new Error(
|
||||||
|
"Fetch API is not available. Please use buildIsomorpicApiClient."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const baseUrl = new URL(document.documentURI);
|
const baseUrl = new URL(document.documentURI);
|
||||||
baseUrl.hash = "";
|
baseUrl.hash = "";
|
||||||
|
|
@ -48,7 +50,9 @@ export function buildRemoteApiClient(
|
||||||
jwt: string
|
jwt: string
|
||||||
): LibreCcmApiClient {
|
): LibreCcmApiClient {
|
||||||
if (!isFetchAvailable()) {
|
if (!isFetchAvailable()) {
|
||||||
throw "Fetch API is not available. Please use buildIsomorpicApiClient.";
|
throw new Error(
|
||||||
|
"Fetch API is not available. Please use buildIsomorpicApiClient."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ApiClientFetchImpl(baseUrl, {
|
return new ApiClientFetchImpl(baseUrl, {
|
||||||
|
|
@ -118,8 +122,16 @@ export function assertProperties(
|
||||||
): void {
|
): void {
|
||||||
const missing = findMissingProperties(record, properties);
|
const missing = findMissingProperties(record, properties);
|
||||||
if (missing.length > 0) {
|
if (missing.length > 0) {
|
||||||
throw `record is missing the following required properties:
|
throw new MissingPropertiesError(missing);
|
||||||
${missing.join(",")}`;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MissingPropertiesError extends Error {
|
||||||
|
constructor(missingProperties: string[]) {
|
||||||
|
super(`record is missing the following required properties:
|
||||||
|
${missingProperties.join(",")}`);
|
||||||
|
|
||||||
|
this.name = "MissingPropertiesError";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue