diff --git a/sdks/js/package.json b/sdks/js/package.json index 3831b79..fd4f560 100644 --- a/sdks/js/package.json +++ b/sdks/js/package.json @@ -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", diff --git a/sdks/js/src/api.ts b/sdks/js/src/api.ts index 2258dc3..83ea2c0 100644 --- a/sdks/js/src/api.ts +++ b/sdks/js/src/api.ts @@ -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}`, }; } }