Files
MobilityOps/n8n/workflows/fleet-ops-error-handler.json
T
NuklearRabbitandClaude Sonnet 5 e39c0a1dd6 n8n: build and live-validate the Workflow Error Handler (WF4)
New central "Fleet Ops — Workflow Error Handler" workflow (Error
Trigger -> safe-report Code node -> POST to the new /workflow-error
endpoint), wired as the Error Workflow on both existing workflows with
no recursive loop on itself. Live-validated end-to-end against the
real Fleet Ops server (register + idempotent re-register), and via a
genuine induced failure on the scheduled-scan workflow (broken URL,
confirmed failure, reverted, confirmed healthy).

Fixed two real bugs found during live testing: Code node needed
"Run Once for Each Item" (not "All Items") for $json binding, and
every HTTP body field had a stray trailing space from the n8n
code-editor's bracket auto-close that broke datetime/enum validation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-04 15:52:17 +02:00

76 lines
3.8 KiB
JSON

{
"id": "Xppn2rAEqUuyiCJF",
"name": "Fleet Ops — Workflow Error Handler",
"nodes": [
{
"parameters": {},
"id": "error-trigger-node",
"name": "Error Trigger",
"type": "n8n-nodes-base.errorTrigger",
"typeVersion": 1,
"position": [240, 300]
},
{
"parameters": {
"mode": "each",
"jsCode": "const err = $json.execution?.error || {};\nconst rawMessage = String(err.message || err.description || 'Unknown error').replace(/[\\r\\n]+/g, ' ').slice(0, 490);\nconst lower = rawMessage.toLowerCase();\nlet category = 'unknown';\nif (lower.includes('timeout') || lower.includes('timed out')) category = 'timeout';\nelse if (lower.includes('401') || lower.includes('403') || lower.includes('unauthorized') || lower.includes('forbidden')) category = 'authError';\nelse if (lower.includes('econnrefused') || lower.includes('enotfound') || lower.includes('network')) category = 'connectionError';\nelse if (/\\b[45]\\d\\d\\b/.test(rawMessage)) category = 'httpError';\nelse if (lower.includes('valid')) category = 'validationError';\nconst workflow = $json.workflow || {};\nconst execution = $json.execution || {};\nreturn {\n json: {\n workflow_id: String(workflow.id || 'unknown'),\n workflow_name: String(workflow.name || 'unknown'),\n execution_id: String(execution.id || ('unknown-' + Date.now())),\n failed_at: new Date().toISOString(),\n error_category: category,\n error_summary: rawMessage,\n trigger_context: String(execution.mode || 'unknown').slice(0, 200),\n correlation_id: null,\n attempt: execution.retryOf ? 2 : 1,\n retry_action: 'No automatic in-workflow retry. Check n8n execution history and the Fleet Ops Automation page for redelivery status.'\n }\n};"
},
"id": "build-report-node",
"name": "Build safe error report",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [500, 300]
},
{
"parameters": {
"method": "POST",
"url": "http://192.168.10.150:1236/api/v1/integrations/n8n/workflow-error",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"contentType": "json",
"specifyBody": "keypair",
"bodyParameters": {
"parameters": [
{ "name": "workflow_id", "value": "={{ $json.workflow_id }}" },
{ "name": "workflow_name", "value": "={{ $json.workflow_name }}" },
{ "name": "execution_id", "value": "={{ $json.execution_id }}" },
{ "name": "failed_at", "value": "={{ $json.failed_at }}" },
{ "name": "error_category", "value": "={{ $json.error_category }}" },
{ "name": "error_summary", "value": "={{ $json.error_summary }}" },
{ "name": "trigger_context", "value": "={{ $json.trigger_context }}" },
{ "name": "correlation_id", "value": "={{ $json.correlation_id }}" },
{ "name": "attempt", "value": "={{ $json.attempt }}" },
{ "name": "retry_action", "value": "={{ $json.retry_action }}" }
]
},
"options": {}
},
"id": "report-node",
"name": "Report failure to Fleet Ops",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [760, 300],
"credentials": {
"httpHeaderAuth": { "name": "Fleet Ops Service Token" }
}
}
],
"connections": {
"Error Trigger": {
"main": [[{ "node": "Build safe error report", "type": "main", "index": 0 }]]
},
"Build safe error report": {
"main": [[{ "node": "Report failure to Fleet Ops", "type": "main", "index": 0 }]]
}
},
"settings": {
"executionOrder": "v1"
},
"active": true,
"meta": {
"templateCredsSetupCompleted": false
},
"tags": []
}