{
  "name": "Invoice Follow-up — Error Handler",
  "nodes": [
    {
      "parameters": {},
      "id": "error-trigger-1",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Format the error payload into a Gotify-friendly message\nconst err = $input.first().json;\nconst workflowName = err.workflow?.name || 'unknown workflow';\nconst nodeName = err.execution?.lastNodeExecuted || 'unknown node';\nconst errorMessage = err.execution?.error?.message || 'no error message';\nconst executionId = err.execution?.id || 'no id';\nconst executionUrl = err.execution?.url || '';\n\nconst title = `n8n FAILURE: ${workflowName}`;\nconst message = `Node: ${nodeName}\\nError: ${errorMessage}\\nExecution: ${executionId}\\n${executionUrl}`;\n\nreturn { title, message, priority: 8 };"
      },
      "id": "format-error-1",
      "name": "Format Error Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.GOTIFY_URL }}/message?token={{ $env.GOTIFY_TOKEN }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ title: $json.title, message: $json.message, priority: $json.priority }) }}",
        "options": {}
      },
      "id": "gotify-alert-1",
      "name": "Gotify Error Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Format Error Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Error Payload": {
      "main": [
        [
          {
            "node": "Gotify Error Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
