refactor: config object is fully optional for SDK js, message for errors
ci/woodpecker/push/woodpecker Pipeline was successful Details

feat/plugins-backend
Tomáš Mládek 2024-04-03 11:00:25 +02:00
parent 196447da0f
commit f9037a4370
2 changed files with 10 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@upnd/upend",
"version": "0.5.0",
"version": "0.5.1",
"description": "Client library to interact with the UpEnd system.",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@ -24,6 +24,7 @@ export type { AddressComponents };
export type UpendApiError = {
kind: "Unauthorized" | "HttpError" | "FetchError" | "Unknown";
message?: string;
error?: Error;
};
@ -37,18 +38,18 @@ export class UpEndApi {
private key: string | undefined;
private readonly onError: ((error: UpendApiError) => void) | undefined;
constructor(config: {
constructor(config?: {
instanceUrl?: string;
wasmExtensions?: UpEndWasmExtensions;
timeout?: number;
authKey?: string;
onError?: (error: UpendApiError) => void;
}) {
this.setInstanceUrl(config.instanceUrl || "http://localhost:8093");
this.wasmExtensions = config.wasmExtensions;
this.timeout = config.timeout || 30_000;
this.key = config.authKey;
this.onError = config.onError;
this.setInstanceUrl(config?.instanceUrl || "http://localhost:8093");
this.wasmExtensions = config?.wasmExtensions;
this.timeout = config?.timeout || 30_000;
this.key = config?.authKey;
this.onError = config?.onError;
}
public setInstanceUrl(apiUrl: string) {
@ -488,13 +489,11 @@ export class UpEndApi {
});
if (!result.ok) {
if (result.status === 401) {
error = { kind: "Unauthorized" };
error = { kind: "Unauthorized", message: await result.text() };
} else {
error = {
kind: "HttpError",
error: new Error(
`HTTP Error ${result.status}: ${result.statusText}`,
),
message: `HTTP Error ${result.status}: ${result.statusText}`,
};
}
}