From 99e015c87e435b61b3f83ab47923bc5c1be14c0a Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Wed, 1 May 2024 18:05:14 +0300 Subject: [PATCH] fix: Error type name is returned - Fixed error parsing in the JS client --- chromadb/server/fastapi/__init__.py | 2 +- clients/js/src/ChromaFetch.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/chromadb/server/fastapi/__init__.py b/chromadb/server/fastapi/__init__.py index 51f50dbe7e3..6c670fadd9b 100644 --- a/chromadb/server/fastapi/__init__.py +++ b/chromadb/server/fastapi/__init__.py @@ -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 ) diff --git a/clients/js/src/ChromaFetch.ts b/clients/js/src/ChromaFetch.ts index 7a7596af534..d5aef89dfe7 100644 --- a/clients/js/src/ChromaFetch.ts +++ b/clients/js/src/ChromaFetch.ts @@ -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); @@ -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: @@ -85,7 +97,7 @@ export const chromaFetch: FetchAPI = async ( } if (respBody?.error) { - throw parseServerError(respBody.error); + throw parseServerError(respBody.error, respBody?.message); } return resp;