Using n8n-nodes-data-validation

Anyone have experience or examples of using [

n8n-nodes-data-validation

](n8n-nodes-data-validation - npm) ?

Specifically I want to understand how to process the result when the JSON does not match the Schema, and how I grab and use the error message in subsequent nodes.

I have tried various settings for “On Error” but I can’t get any data into the following node

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @Russell_Hutson

I am not familiar with this community node.
But it would help if you showed the parameters not the node settings.
Also probably best to ask the creator of the node if it isn’t something obvious in the parameters.

thanks, the node settings are just a JSON Scheme I am using to test this node’s functionality, so I just have a schema like

{
  "type": "object",
  "required": [
    "HashedPAN",
    "ExpiryYear",
    "ExpiryMonth"
  ],
  "properties": {
    "CardId": {
      "type": "integer"
    },
    "HashedPAN": {
      "type": "string"
    },
    "ExpiryYear": {
      "type": "integer",
      "minimum": 2000
    },
    "ExpiryMonth": {
      "type": "integer",
      "minimum": 4,
      "maximum": 12
    },
    "ModifiedOn": {
      "type": "string"
    }
  }
}

If I expiryMonth’s min and max to 1 & 12 then my JOSN Validates as expected and my output is

[
  {
    "HashedPAN": "Visa***1199",
    "ExpiryYear": 2028,
    "ExpiryMonth": 3
  }
]

and nothing gets sent to the Error Branch.

But if my JSON does not validate against the Schema, then this node throws an NodeAPIError() and I see and Invalid Data error like the one above.

      if (!valid) {
        throw new NodeApiError(
          this.getNode(),
          {
            errors: JSON.stringify(validate.errors, undefined, 4),
          },
          {
            itemIndex,
            message: "Invalid data",
            description: JSON.stringify(validate.errors, undefined, 4),
            httpCode: "400",
          }
        );
      }

Not sure if the 400 error is by design or not.

Is there a way to catch Node errors like this and inspect the data? I could use the “message” in the thrown error.

Ahh I see, that is not how I would have designed it.
If the error returned doesn’t show the complete error in the data returned there is nothing you can do about it I think.
So it would need to be changed in the node itself to pass this message properly.

thanks. Looks like I need to fork the node to fix this

Not sure how active the creator is but you might be able to work with them to fix it.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.