fix: serialize vectordb client errors as json (#1795)

This commit is contained in:
Bert
2024-11-05 14:16:25 -05:00
committed by GitHub
parent 26f4a80e10
commit 4e8c7b0adf

View File

@@ -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 })
}