8
n8n 中文网amn8n.com

AIAutomationPro 高级错误处理与邮件通知 v1

高级

这是一个Engineering, DevOps领域的自动化工作流,包含 16 个节点。主要使用 If, N8n, Set, Code, Html 等节点。 集中式n8n错误管理系统,通过Gmail自动发送邮件警报

前置要求
  • Google 账号和 Gmail API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "KhpM42Ckgy6qgzCz",
  "meta": {
    "instanceId": "b3df22d2875c82e3ba1883c50049ed9cee0bcabf99d2b486961d2245a09e3964",
    "templateId": "2312",
    "templateCredsSetupCompleted": true
  },
  "name": "AIAutomationPro 高级错误处理与邮件通知 v1",
  "tags": [],
  "nodes": [
    {
      "id": "7b9a99ba-2e76-4210-a2e5-cb5c9fd707a7",
      "name": "错误触发器",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        460,
        800
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "301a2f94-187c-4183-a0fc-5ec30480202a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1080,
        580
      ],
      "parameters": {
        "width": 783,
        "height": 549,
        "content": "## 发送错误处理邮件"
      },
      "typeVersion": 1
    },
    {
      "id": "f624fcc6-ea87-425c-b20c-b8c14d7f1226",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        460,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "dedfb0a6-a297-42c3-8a68-6aded7203373",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        220
      ],
      "parameters": {
        "width": 1195,
        "height": 260,
        "content": "## 为所有 N8N 工作流更新默认错误处理器"
      },
      "typeVersion": 1
    },
    {
      "id": "2de34694-ccc8-451d-9bd7-9b438d5d045b",
      "name": "N8N 获取错误处理器",
      "type": "n8n-nodes-base.n8n",
      "position": [
        760,
        300
      ],
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "S63rln42rAvGFfBB",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c5ac588c-3972-4b32-9d40-dbb5a73cb170",
      "name": "N8N 获取所有工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        980,
        300
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "S63rln42rAvGFfBB",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ad17b29e-18c9-4ac9-8b87-67c79ca2b0a4",
      "name": "如果未设置默认错误处理器",
      "type": "n8n-nodes-base.if",
      "position": [
        1200,
        300
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "290fd302-4e2d-44d6-8a8a-14a0b8f2c360",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.settings.errorWorkflow }}",
              "rightValue": "=Default Error Handler"
            },
            {
              "id": "2a5799e9-2030-4281-bf11-e7f9777906c5",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": "={{ $('N8n Get Error Handler').first().json.id }}"
            },
            {
              "id": "6059514d-9bef-4d21-a52e-eb967aea84f7",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.active }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "19439590-b2a7-4884-9280-16955e1cf895",
      "name": "N8N 更新工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1640,
        280
      ],
      "parameters": {
        "operation": "update",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "requestOptions": {},
        "workflowObject": "={{ JSON.stringify($json) }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "S63rln42rAvGFfBB",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4c1bb8fe-8029-4cf1-9b96-c17d54145340",
      "name": "设置数据",
      "type": "n8n-nodes-base.code",
      "position": [
        1420,
        280
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const data = $json\n\ndata.settings.errorWorkflow = $('N8n Get Error Handler').item.json.id ;\ndelete data.settings.callerPolicy;\n\nreturn {\n  id: data.id,\n  name: data.name,\n  nodes: data.nodes,\n  connections: data.connections,\n  settings: data.settings\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "4d8b7522-62ae-4738-9c48-285363399b0a",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        720
      ],
      "parameters": {
        "width": 300,
        "height": 260,
        "content": "## 设置"
      },
      "typeVersion": 1
    },
    {
      "id": "a6a452ec-5320-46b3-be99-cf6b3f562de2",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "position": [
        760,
        800
      ],
      "parameters": {
        "options": {
          "dotNotation": true
        },
        "assignments": {
          "assignments": [
            {
              "id": "53ac5417-db98-41e5-bc6d-acb6dd1fec42",
              "name": "N8n Url",
              "type": "string",
              "value": "={{ $('Error Trigger').first().json.execution.url.split('executions')[0] }}"
            },
            {
              "id": "0f85c65a-80bb-4977-90b9-1b4e741b5f70",
              "name": "Email Receiver",
              "type": "string",
              "value": "your-email-here@gmail.com"
            },
            {
              "id": "138c091f-7cd4-453a-9c75-5d193b617a39",
              "name": "Email Sender Name",
              "type": "string",
              "value": "Error Handling System"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "a357bfaf-66d4-4b35-b4e8-8e4dbc255a68",
      "name": "如果执行错误",
      "type": "n8n-nodes-base.if",
      "position": [
        1200,
        800
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a757d78d-799b-401b-8c01-3103fddfe757",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ Boolean($('Settings').first().json.execution) }}",
              "rightValue": "={{ true }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f72827ca-6775-45d1-923b-0ced413a7b25",
      "name": "用于执行错误的 HTML",
      "type": "n8n-nodes-base.html",
      "position": [
        1420,
        680
      ],
      "parameters": {
        "html": "<h2>Execution Details</h2>\n<p>Please see execution details at <a href=\"{{ $('Settings').first().json.execution.url }}\">workflow execution url</a></p>\n<h3>DateTime</h3>\n<p>{{ DateTime.fromMillis($json.execution.error.timestamp) }}</p>\n<h3>Last Node Executed</h3>\n<p>{{ $json.execution.lastNodeExecuted }}</p>\n<h3>Mode</h3>\n<p>{{ $json.execution.mode }}</p>\n<h3>Message</h3>\n<p>{{ $json.execution.error.message }}</p>\n<h3>Stack trace</h3>\n<pre>\n{{ $json.execution.error.stack }}\n</pre>"
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "c0dc9576-73f4-44f6-b82b-c056e40ec693",
      "name": "用于触发器错误的 HTML",
      "type": "n8n-nodes-base.html",
      "position": [
        1420,
        920
      ],
      "parameters": {
        "html": "<h2>Trigger Failure Details</h2>\n<p>A trigger on main workflow has thrown an error.</p>\n<h3>DateTime</h3>\n<p>{{ DateTime.fromMillis($json.trigger.error.timestamp) }}</p>\n<h3>Mode</h3>\n<p>{{ $json.trigger.mode }}</p>\n<h3>Message</h3>\n<p>{{ $json.trigger.error.message }}</p>\n<h3>Name</h3>\n<p>{{ $json.trigger.error.name }}</p>\n<h3>Description</h3>\n<p>{{ $json.trigger.error.description }}</p>\n<h3>Context</h3>\n<pre>{{ JSON.stringify($json.trigger.error.context, null, 2) }}</pre>\n\n<h3>Cause</h3>\n<p>Message: {{ $json.trigger.error.cause.message }}</p>\n<p>Name: {{ $json.trigger.error.cause.name }}</p>\n<p>Code:{{ $json.trigger.error.cause.code }} </p>\n<p>Status: {{ $json.trigger.error.cause.status }}</p>\n<h3>Stack trace</h3>\n<pre>\n{{ $json.trigger.error.cause.stack }}\n</pre>"
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "b497eb7b-a9b3-41f6-a71b-d614d20f2402",
      "name": "Gmail 发送通知",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1640,
        800
      ],
      "webhookId": "d9c9328c-5be7-4ebe-a20a-c025e52cdf46",
      "parameters": {
        "sendTo": "={{ $('Settings').first().json['Email Receiver'] }}",
        "message": "={{ $json.html }}\n",
        "options": {
          "senderName": "={{ $('Settings').first().json['Email Sender Name'] }}",
          "appendAttribution": false
        },
        "subject": "=[N8N Alert] Issue Detected In Workflow ({{ $('Settings').first().json.workflow.name }}) - {{ Boolean($('Settings').first().json.execution) ? \"Execution Error\" : \"Trigger Failure\" }}: {{ $('Settings').first().json.execution.error.message || $('Settings').first().json.trigger.error.message }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "HOfMnLio66bOO80m",
          "name": "Ai Auto Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "34b07331-bf9e-453e-89de-1c51fa094642",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        140
      ],
      "parameters": {
        "width": 740,
        "height": 3080,
        "content": "## **高级 n8n 错误处理:自动化邮件提醒与全局错误工作流配置**"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {
    "Error Trigger": [
      {
        "json": {
          "trigger": {
            "mode": "trigger",
            "error": {
              "name": "NodeApiError",
              "cause": {
                "code": "ERR_BAD_RESPONSE",
                "name": "AxiosError",
                "stack": "AxiosError: Request failed with status code 503\n    at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:19:12)\n    at Unzip.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:599:11)\n    at Unzip.emit (node:events:536:35)\n    at endReadableNT (node:internal/streams/readable:1698:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)\n    at Axios.request (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/Axios.js:45:41)\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at invokeAxios (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/node-execution-context/utils/request-helper-functions.js:173:16)\n    at proxyRequestToAxios (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/node-execution-context/utils/request-helper-functions.js:513:26)\n    at Object.request (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/node-execution-context/utils/request-helper-functions.js:1145:50)\n    at PollContext.requestOAuth2 (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/node-execution-context/utils/request-helper-functions.js:792:12)\n    at PollContext.requestOAuth2 (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/node-execution-context/utils/request-helper-functions.js:1153:20)\n    at PollContext.apiRequest (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Google/Sheet/v2/transport/index.js:68:14)\n    at GoogleSheet.spreadsheetGetSheet (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Google/Sheet/v2/helpers/GoogleSheet.js:121:22)\n    at PollContext.poll (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Google/Sheet/GoogleSheetsTrigger.node.js:402:45)\n    at TriggersAndPollers.runPoll (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/triggers-and-pollers.js:59:16)\n    at executeTrigger (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/active-workflows.js:78:38)",
                "status": 503,
                "message": "503 - {\"error\":{\"code\":503,\"message\":\"The service is currently unavailable.\",\"status\":\"UNAVAILABLE\"}}"
              },
              "context": {},
              "message": "Service unavailable - try again later or consider setting this node to retry automatically (in the node settings)",
              "timestamp": 1748605421337,
              "description": "The service is currently unavailable."
            }
          },
          "workflow": {
            "id": "dm2trOGY525Nr10K",
            "name": "(Duc) WordPress Blog Automation Pro (Deep Research) v1"
          }
        }
      }
    ]
  },
  "settings": {},
  "versionId": "b0e4a2b2-8787-4b7d-b8fc-ccf1b36a0ddd",
  "connections": {
    "Set Data": {
      "main": [
        [
          {
            "node": "N8n Update Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "If Execution Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "N8n Get Error Handler",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Execution Error": {
      "main": [
        [
          {
            "node": "HTML For Execution Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTML For Trigger Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "N8n Get All Workflows": {
      "main": [
        [
          {
            "node": "If No Default Error Handler Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "N8n Get Error Handler": {
      "main": [
        [
          {
            "node": "N8n Get All Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML For Trigger Error": {
      "main": [
        [
          {
            "node": "Gmail Send Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML For Execution Error": {
      "main": [
        [
          {
            "node": "Gmail Send Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If No Default Error Handler Set": {
      "main": [
        [
          {
            "node": "Set Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 工程, 开发运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类2
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Daniel Ng

Daniel Ng

@danielng

A Growth Hacker, Digital Marketer & AI Automation Builder with 10+ years of experience in Digital Marketing & Workflow Automation. Based in Helsinki, Finland. For questions about my templates and customization, contact me at: daniel@aiautomationpro.org

外部链接
在 n8n.io 查看

分享此工作流