Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] JS admin client should throw well-formatted errors rather than Responses #2106

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my understanding, why does this result in well formatted errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromaFetch is a wrapper around fetch() that will throw Errors based on the response status code

by default, the autogenerated client seems to throw Responses

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

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);
}
});
Loading