commit 466743206fa52e828131dc922578a96a0b1742f1 parent 75f2ee62b43a61c9ba9700d306366a07fcd2d494 Author: triesap <triesap@radroots.dev> Date: Fri, 21 Nov 2025 01:14:15 +0000 utils: refactor http response parsing with improved return typing and json-to-text fallback Diffstat:
| M | utils/src/http.ts | | | 15 | +++++++++------ |
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/utils/src/http.ts b/utils/src/http.ts @@ -99,14 +99,17 @@ export const http_fetch_opts = (opts: IHttpOpts): { url: string; options: Reques } }; -export const lib_http_parse_response = async (res: Response): Promise<Promise<IHttpResponse>> => { - let data: any = null; +export const lib_http_parse_response = async (res: Response): Promise<IHttpResponse> => { + let data: unknown = null; try { - const res_json = await res.json(); - if (typeof res_json === `string`) data = JSON.parse(res_json); - else data = res_json; + const res_json = await res.clone().json(); + data = typeof res_json === `string` ? JSON.parse(res_json) : res_json; } catch { } - if (!data) data = await res.text(); + if (!data) { + try { + data = await res.text(); + } catch { } + } return { status: res.status, url: res.url,