ZZZ Digital Lab

Back to n8n workflow hardening

after/error-workflow.json

{
  "id": "SYNTHETIC_ERROR_WORKFLOW_ID",
  "name": "SYNTHETIC - Error incident delivery",
  "active": false,
  "nodes": [
    {
      "id": "workflow-error",
      "name": "Workflow Error",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "build-incident",
      "name": "Build Incident",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// SYNTHETIC. Safe summary, no raw error stack or payload forwarded to incident sink.\nconst input = $input.first().json;\nconst identity = input.execution?.id || input.trigger?.timestamp;\nif (!identity) throw new Error('INCIDENT_ID_MISSING');\nreturn [{json:{synthetic:true,incident_key:'incident:' + String(identity),\n  workflow_id:String(input.workflow?.id || 'unknown').slice(0,80),\n  reason:'WORKFLOW_FAILED',action:'Inspect local execution and dead-letter store'}}];\n"
      }
    },
    {
      "id": "persist-incident",
      "name": "Persist Incident",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        0
      ],
      "parameters": {
        "method": "PUT",
        "url": "={{ 'https://incident-sink.example.invalid/incidents/' + encodeURIComponent($json.incident_key) }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $json.incident_key }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {
          "timeout": 5000,
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 100
            }
          }
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "SYNTHETIC_PERSIST_INCIDENT_CREDENTIAL_ID",
          "name": "Configure locally - Persist Incident"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 1000,
      "onError": "stopWorkflow"
    }
  ],
  "connections": {
    "Workflow Error": {
      "main": [
        [
          {
            "node": "Build Incident",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Incident": {
      "main": [
        [
          {
            "node": "Persist Incident",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 300,
    "saveDataSuccessExecution": "none",
    "saveDataErrorExecution": "all"
  },
  "pinData": {},
  "tags": []
}