1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

ensure JSON parsed correctly

This commit is contained in:
Martin McKeaveney 2021-02-15 19:57:49 +00:00
parent 5d5637571b
commit 13c51f61d9
2 changed files with 12 additions and 6 deletions

View file

@ -67,10 +67,16 @@ async function enrichQueryFields(fields, parameters) {
} }
} }
if (enrichedQuery.json || enrichedQuery.customData) { if (
enrichedQuery.json ||
enrichedQuery.customData ||
enrichedQuery.requestBody
) {
try { try {
enrichedQuery.json = JSON.parse( enrichedQuery.json = JSON.parse(
enrichedQuery.json || enrichedQuery.customData enrichedQuery.json ||
enrichedQuery.customData ||
enrichedQuery.requestBody
) )
} catch (err) { } catch (err) {
throw { message: `JSON Invalid - error: ${err}` } throw { message: `JSON Invalid - error: ${err}` }

View file

@ -72,11 +72,11 @@ class RestIntegration {
this.config = config this.config = config
} }
async create({ path, headers = {}, requestBody }) { async create({ path, headers = {}, json }) {
const response = await fetch(this.config.url + path, { const response = await fetch(this.config.url + path, {
method: "POST", method: "POST",
headers, headers,
body: requestBody, body: JSON.stringify(json),
}) })
return await response.json() return await response.json()
@ -90,11 +90,11 @@ class RestIntegration {
return await response.json() return await response.json()
} }
async update({ path, headers = {}, requestBody }) { async update({ path, headers = {}, json }) {
const response = await fetch(this.config.url + path, { const response = await fetch(this.config.url + path, {
method: "POST", method: "POST",
headers, headers,
body: requestBody, body: JSON.stringify(json),
}) })
return await response.json() return await response.json()