{
 "name": "RecipeAgents: Error handler (email me when a workflow fails)",
 "nodes": [
  {
   "parameters": {},
   "id": "89fc85f3-bd7d-53e4-b8bb-a57631138beb",
   "name": "Error Trigger",
   "type": "n8n-nodes-base.errorTrigger",
   "typeVersion": 1,
   "position": [
    240,
    300
   ]
  },
  {
   "parameters": {
    "jsCode": "// Turns the Error Trigger data into a short alert.\n// Two shapes exist (n8n docs): a failed run has execution{}, a failed trigger has trigger{} and no execution id or link.\nconst e = $input.first().json;\nconst wf = (e.workflow && e.workflow.name) || 'Unknown workflow';\nconst cut = (s) => String(s || '').slice(0, 600);\nlet subject, lines;\nif (e.execution) {\n  const x = e.execution;\n  subject = `n8n workflow failed: ${wf}`;\n  lines = [\n    `Workflow: ${wf}`,\n    `Failed at node: ${x.lastNodeExecuted || 'unknown'}`,\n    `Error: ${cut(x.error && x.error.message)}`,\n    `Run mode: ${x.mode || 'unknown'}`,\n    x.url ? `Open the run: ${x.url}` : 'No run link: the execution was not saved.',\n  ];\n} else {\n  const t = e.trigger || {};\n  subject = `n8n trigger failed: ${wf}`;\n  lines = [\n    `Workflow: ${wf}`,\n    'The trigger itself failed, so the workflow never started (no run to open).',\n    `Error: ${cut(t.error && t.error.message)}`,\n    `Trigger node: ${(t.error && t.error.node && t.error.node.name) || 'unknown'}`,\n  ];\n}\nreturn [{ json: { subject, body: lines.join('\\n') } }];"
   },
   "id": "911f7566-e14e-50f1-b68b-9106621c2a62",
   "name": "Build alert",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    500,
    300
   ]
  },
  {
   "parameters": {
    "sendTo": "you@example.com",
    "subject": "={{ $json.subject }}",
    "emailType": "text",
    "message": "={{ $json.body }}",
    "options": {}
   },
   "id": "2cc923e4-6bd0-56b7-9b7c-dfc75a22a43f",
   "name": "Email me",
   "type": "n8n-nodes-base.gmail",
   "typeVersion": 2.1,
   "position": [
    760,
    300
   ]
  }
 ],
 "connections": {
  "Error Trigger": {
   "main": [
    [
     {
      "node": "Build alert",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Build alert": {
   "main": [
    [
     {
      "node": "Email me",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "pinData": {},
 "active": false,
 "settings": {
  "executionOrder": "v1"
 },
 "meta": {
  "templateCredsSetupCompleted": false
 },
 "tags": []
}
