Skip to content

Commit

Permalink
[ENH] JS admin client should throw well-formatted errors rather than …
Browse files Browse the repository at this point in the history
…Responses (#2106)
  • Loading branch information
codetheweb authored May 2, 2024
1 parent ef451c8 commit b0b089a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clients/js/src/AdminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
authOptionsToAuthProvider,
ClientAuthProvider,
} from "./auth";
import { chromaFetch } from "./ChromaFetch";

const DEFAULT_TENANT = "default_tenant";
const DEFAULT_DATABASE = "default_database";
Expand Down Expand Up @@ -64,7 +65,7 @@ export class AdminClient {
basePath: path,
});

this.api = new DefaultApi(apiConfig);
this.api = new DefaultApi(apiConfig, undefined, chromaFetch);
this.api.options = fetchOptions ?? {};

if (auth !== undefined) {
Expand Down
11 changes: 11 additions & 0 deletions clients/js/test/admin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "@jest/globals";
import { AdminClient } from "../src/AdminClient";
import adminClient from "./initAdminClient";
import { ChromaError } from "../src/Errors";

test("it should create the admin client connection", async () => {
expect(adminClient).toBeDefined();
Expand Down Expand Up @@ -64,3 +65,13 @@ test("it should set the tenant and database", async () => {

expect(adminClient.database).toBe("testDatabase2");
});

test("it should throw well-formatted errors", async () => {
try {
await adminClient.createDatabase({ name: "test", tenantName: "foo" });
expect(false).toBe(true);
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(ChromaError);
}
});

0 comments on commit b0b089a

Please sign in to comment.