refactor: config object is fully optional for SDK js, message for errors
This commit is contained in:
parent
0c304b55d8
commit
5de0780ab5
2 changed files with 10 additions and 11 deletions
|
@ -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",
|
||||
|
|
|
@ -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}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue