From 33cfe57900b801248082c76ecd2e5e8e1fcc41cc Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Mon, 28 Oct 2024 07:57:58 +0100 Subject: [PATCH] Fix ocr errors showing as `[object Object]` --- apps/server-asset-sg/src/features/files/file-ocr.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/server-asset-sg/src/features/files/file-ocr.service.ts b/apps/server-asset-sg/src/features/files/file-ocr.service.ts index ebaf93d7..10ae85a1 100644 --- a/apps/server-asset-sg/src/features/files/file-ocr.service.ts +++ b/apps/server-asset-sg/src/features/files/file-ocr.service.ts @@ -171,8 +171,12 @@ const makeResponseError = async (response: Response): Promise => { if (hasKey(data, 'message')) { data = data.message; } + } else if (hasKey(data, 'message')) { + data = data.message; } - return new Error(`${response.status} ${response.statusText} - ${data ?? body}`); + data = data ?? body; + const message = typeof data === 'string' ? data : JSON.stringify(data); + return new Error(`${response.status} ${response.statusText} - ${message}`); }; const hasKey = (value: unknown, key: K): value is { [k in K]: unknown } => {