Skip to content

Commit

Permalink
fix: Error type name is returned
Browse files Browse the repository at this point in the history
- Fixed error parsing in the JS client
  • Loading branch information
tazarov committed May 1, 2024
1 parent c297669 commit 99e015c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def catch_exceptions_middleware(
except Exception as e:
logger.exception(e)
return JSONResponse(
content={"error": str(type(e)), "message": f"{str(e)}"}, status_code=500
content={"error": type(e).__name__, "message": f"{str(e)}"}, status_code=500
)


Expand Down
18 changes: 15 additions & 3 deletions clients/js/src/ChromaFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ function isOfflineError(error: any): boolean {
);
}

function parseServerError(error: string | undefined): Error {
function parseServerError(
error: string | undefined,
message: string | undefined,
): Error {
const regex = /(\w+)\('(.+)'\)/;
const match = error?.match(regex);
if (error && message) {
switch (error) {
case "ValueError":
return new ChromaValueError(message);
default:
return new ChromaError(error, message);
}
}
if (match) {
const [, name, message] = match;

switch (name) {
case "ValueError":
return new ChromaValueError(message);
Expand Down Expand Up @@ -71,7 +83,7 @@ export const chromaFetch: FetchAPI = async (
`The requested resource could not be found: ${input}`,
);
case 500:
throw parseServerError(respBody?.error);
throw parseServerError(respBody?.error, respBody?.message);
case 502:
case 503:
case 504:
Expand All @@ -85,7 +97,7 @@ export const chromaFetch: FetchAPI = async (
}

if (respBody?.error) {
throw parseServerError(respBody.error);
throw parseServerError(respBody.error, respBody?.message);
}

return resp;
Expand Down

0 comments on commit 99e015c

Please sign in to comment.