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",
|
"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",
|
||||||
|
|
|
@ -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}`,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue