fix: ensure custom request data must be JSON (#6701)

This commit is contained in:
chenos 2025-04-18 11:15:06 +08:00 committed by GitHub
parent e1e2f7a83c
commit 88dd0c84e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,6 +15,17 @@ import Application from '@nocobase/server';
import axios from 'axios';
import CustomRequestPlugin from '../plugin';
function toJSON(value) {
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch (error) {
return value;
}
}
return value;
}
const getHeaders = (headers: Record<string, any>) => {
return Object.keys(headers).reduce((hds, key) => {
if (key.toLocaleLowerCase().startsWith('x-')) {
@ -168,7 +179,7 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next)
...omitNullAndUndefined(getParsedValue(arrayToObject(headers), variables)),
},
params: getParsedValue(arrayToObject(params), variables),
data: getParsedValue(data, variables),
data: getParsedValue(toJSON(data), variables),
};
const requestUrl = axios.getUri(axiosRequestConfig);