{
  "name": "Vorlux AI | Centralized Error Handler",
  "nodes": [
    {
      "id": "f2ce2be3-9f03-4b7b-b19b-47d104b77d06",
      "name": "Error Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "webhookId": "d3bbae6e-8ff7-441b-ad0f-eb75afd86832",
      "parameters": {
        "httpMethod": "POST",
        "path": "workflow-error",
        "options": {
          "responseMode": "lastNode"
        }
      }
    },
    {
      "id": "81b8cec1-2ed2-49a5-9741-010f79d8e5f6",
      "name": "Parse Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const d = .first().json.body || .first().json;\nconst workflowName = d.workflow?.name || d.workflowName || 'Unknown';\nconst errorMessage = d.error?.message || d.message || d.error || 'Unknown error';\nconst executionId = d.execution?.id || d.executionId || '';\nconst nodeName = d.error?.node || d.nodeName || '';\nconst timestamp = new Date().toISOString();\nconst severity = errorMessage.toLowerCase().includes('timeout') ? 'warning' : 'error';\nreturn [{json: {workflowName, errorMessage: errorMessage.substring(0, 1000), executionId, nodeName, timestamp, severity}}];"
      },
      "notes": "Extracts error details from any workflow failure"
    },
    {
      "id": "5bb7b188-15f1-4a57-9982-524fae763d6c",
      "name": "Log to DB",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{.VORLUX_HUB_URL}}/api/activity",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"type\":\"workflow_error\",\"action\":\"error\",\"metadata\":{\"workflow\":\"{{ .workflowName }}\",\"error\":\"{{ .errorMessage }}\",\"execution\":\"{{ .executionId }}\",\"node\":\"{{ .nodeName }}\"}}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "d01dff2b-9151-474d-837a-40d29ee13682",
      "name": "Alert Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"{{ .severity === \"error\" ? \"\ud83d\udea8\" : \"\u26a0\ufe0f\" }} Workflow Error: {{ .workflowName }}\",\"description\":\"**Node:** {{ .nodeName }}\\n**Error:** {{ .errorMessage }}\\n**Execution:** {{ .executionId }}\",\"color\":{{ .severity === \"error\" ? 15158332 : 16776960 }},\"timestamp\":\"{{ .timestamp }}\"}]}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "bd93480f-74ec-4f7c-8425-a3a10cce32ef",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        940,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({logged: true, severity: .severity}) }}"
      }
    }
  ],
  "connections": {
    "Error Webhook": {
      "main": [
        [
          {
            "node": "Parse Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Error": {
      "main": [
        [
          {
            "node": "Log to DB",
            "type": "main",
            "index": 0
          },
          {
            "node": "Alert Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to DB": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Discord": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}