Skip to content

Commit dac2b73

Browse files
authored
fix(gatsby-source-drupal): validate webhook bodies & updated node data (#33079)
* fix(gatsby-source-drupal): validate webhook bodies & updated node data Fix some errors we've seen on Drupal sites from updates coming. Ideally we iron out too whatever is triggering malformed/missing updates from coming in. This will at least not break builds + give us some more info to track down the deeper issue. * Clarify warning
1 parent bdf42c9 commit dac2b73

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/gatsby-source-drupal/src/gatsby-node.js

+14
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ exports.sourceNodes = async (
146146
changesActivity.end()
147147
return
148148
}
149+
150+
if (!action || !data) {
151+
reporter.warn(
152+
`The webhook body was malformed
153+
154+
${JSON.stringify(webhookBody, null, 4)}
155+
156+
`
157+
)
158+
159+
changesActivity.end()
160+
return
161+
}
162+
149163
if (action === `delete`) {
150164
let nodesToDelete = data
151165
if (!Array.isArray(data)) {

packages/gatsby-source-drupal/src/utils.js

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ const handleWebhookUpdate = async (
196196
},
197197
pluginOptions = {}
198198
) => {
199+
if (!nodeToUpdate || !nodeToUpdate.attributes) {
200+
reporter.warn(
201+
`The updated node was empty or is missing the required attributes field. The fact you're seeing this warning means there's probably a bug in how we're creating and processing updates from Drupal.
202+
203+
${JSON.stringify(nodeToUpdate, null, 4)}
204+
`
205+
)
206+
207+
return
208+
}
209+
199210
const { createNode } = actions
200211

201212
const newNode = nodeFromData(

0 commit comments

Comments
 (0)