From ff45f25cf28aeab51c0658729ebf608eb3172202 Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 3 Apr 2024 10:24:51 -0400 Subject: [PATCH] fix error decoding in nodejs client (#1184) fixes: #1183 --- node/src/remote/client.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 91fa6857..04f8e43a 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -103,6 +103,18 @@ function toLanceRes (res: AxiosResponse): RemoteResponse { } } +async function decodeErrorData( + res: RemoteResponse, + responseType?: ResponseType +): Promise { + const errorData = await res.body() + if (responseType === 'arraybuffer') { + return new TextDecoder().decode(errorData) + } else { + return errorData + } +} + export class HttpLancedbClient { private readonly _url: string private readonly _apiKey: () => string @@ -180,7 +192,7 @@ export class HttpLancedbClient { } if (response.status !== 200) { - const errorData = new TextDecoder().decode(await response.body()) + const errorData = await decodeErrorData(response) throw new Error( `Server Error, status: ${response.status}, ` + `message: ${response.statusText}: ${errorData}` @@ -226,7 +238,7 @@ export class HttpLancedbClient { } if (response.status !== 200) { - const errorData = new TextDecoder().decode(await response.body()) + const errorData = await decodeErrorData(response, responseType) throw new Error( `Server Error, status: ${response.status}, ` + `message: ${response.statusText}: ${errorData}`