Skip to content

Commit

Permalink
fix(gatsby-source-drupal): validate webhook bodies & updated node data (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
KyleAMathews committed Sep 8, 2021
1 parent bdf42c9 commit dac2b73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ exports.sourceNodes = async (
changesActivity.end()
return
}

if (!action || !data) {
reporter.warn(
`The webhook body was malformed
${JSON.stringify(webhookBody, null, 4)}
`
)

changesActivity.end()
return
}

if (action === `delete`) {
let nodesToDelete = data
if (!Array.isArray(data)) {
Expand Down
11 changes: 11 additions & 0 deletions packages/gatsby-source-drupal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ const handleWebhookUpdate = async (
},
pluginOptions = {}
) => {
if (!nodeToUpdate || !nodeToUpdate.attributes) {
reporter.warn(
`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.
${JSON.stringify(nodeToUpdate, null, 4)}
`
)

return
}

const { createNode } = actions

const newNode = nodeFromData(
Expand Down

0 comments on commit dac2b73

Please sign in to comment.