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", "name": "@upnd/upend",
"version": "0.5.0", "version": "0.5.1",
"description": "Client library to interact with the UpEnd system.", "description": "Client library to interact with the UpEnd system.",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

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