From 4e8c7b0adfb5a1b4d6ac3902405d00b8129ac8e1 Mon Sep 17 00:00:00 2001 From: Bert Date: Tue, 5 Nov 2024 14:16:25 -0500 Subject: [PATCH] fix: serialize vectordb client errors as json (#1795) --- node/src/remote/client.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 01a11f07..cf99a182 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import axios, { type AxiosResponse, type ResponseType } from 'axios' +import axios, { type AxiosError, type AxiosResponse, type ResponseType } from 'axios' import { tableFromIPC, type Table as ArrowTable } from 'apache-arrow' @@ -197,7 +197,7 @@ export class HttpLancedbClient { response = await callWithMiddlewares(req, this._middlewares) return response } catch (err: any) { - console.error('error: ', err) + console.error(serializeErrorAsJson(err)) if (err.response === undefined) { throw new Error(`Network Error: ${err.message as string}`) } @@ -247,7 +247,8 @@ export class HttpLancedbClient { // return response } catch (err: any) { - console.error('error: ', err) + console.error(serializeErrorAsJson(err)) + if (err.response === undefined) { throw new Error(`Network Error: ${err.message as string}`) } @@ -287,3 +288,15 @@ export class HttpLancedbClient { return clone } } + +function serializeErrorAsJson(err: AxiosError) { + const error = JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err))) + error.response = err.response != null + ? JSON.parse(JSON.stringify( + err.response, + // config contains the request data, too noisy + Object.getOwnPropertyNames(err.response).filter(prop => prop !== 'config') + )) + : null + return JSON.stringify({ error }) +}