From 8f0e1ac1d851706996227c1bfa4b03eb59319290 Mon Sep 17 00:00:00 2001 From: ddbdzung Date: Mon, 10 Mar 2025 03:00:16 +0700 Subject: [PATCH] fix: convert Axios body data to JSON string when Content-Type is application/json --- manifest.common.json | 2 +- src/index.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/manifest.common.json b/manifest.common.json index b1a4d0e..6ac57bc 100644 --- a/manifest.common.json +++ b/manifest.common.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Hoppscotch Browser Extension", - "version": "0.37", + "version": "0.38", "description": "Provides more capabilities for Hoppscotch", "icons": { "16": "icons/icon-16x16.png", diff --git a/src/index.ts b/src/index.ts index dd889de..72f6437 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,16 @@ async function fetchUsingAxiosConfig( } catch (_) {} } + try { + const contentType = axiosConfig.headers["content-type"] || ""; + + if (contentType.includes("application/json") && axiosConfig.data && typeof axiosConfig.data !== "string") { + axiosConfig.data = JSON.stringify(axiosConfig.data); + } + } catch (e) { + console.error("Error stringifying axiosConfig.data:", e, axiosConfig.data); + } + // TODO: check different examples with axios body const res = await fetch(axiosConfig.url, { headers: {