Error Handling
ဘာကြောင့် Error Handling လိုအပ်သလဲ?
Section titled “ဘာကြောင့် Error Handling လိုအပ်သလဲ?”Production Workflow တွေမှာ Error တွေ မမျှော်မှန်းထားဘဲ ဖြစ်ပေါ်နိုင်ပါတယ်:
- Network Errors — API Timeout, 503
- Auth Errors — Token Expired, 401
- Data Errors — Wrong Format, Null Value
- Rate Limit — 429 Too Many Requests
- Storage Errors — DB Connection Failed
Error Handling မရှိဘဲ Workflow Fail ဖြစ်ရင် — Data ပျောက်မည်၊ User Notify မရမည်၊ Process မပြည့်စုံမည်။
n8n Error Types
Section titled “n8n Error Types”1. Node Error
Section titled “1. Node Error”Node တစ်ခုသာ Fail ဖြစ်ပြီး Workflow ရပ်တန့်သည်:
HTTP Request Fail ဖြစ်ရင် နောက် Node တွေ မပြေးတော့ပါ
2. Execution Error
Section titled “2. Execution Error”Execution History တွင် Failed Execution တွေ ပြသသည်:
Execution History: ✅ 09:00 - Success (12 items processed) ✅ 09:01 - Success (8 items processed) ❌ 09:02 - FAILED - API returned 500 ✅ 09:03 - Success (5 items processed)Error Handling Strategies
Section titled “Error Handling Strategies”Strategy 1: Node Error Output
Section titled “Strategy 1: Node Error Output”Node တစ်ခု Fail ဖြစ်ရင် Alternative Path တစ်ခု Run သည်:
Node Settings မှ “Continue on Fail” ကို Enable လုပ်ပြီး Error Output Port ကို ချိတ်ဆက်ပါ:
Node Settings: ✅ Always Output Data ✅ Continue On Fail
Error Output: ● Enabled (Red Output Port appears on Node)Strategy 2: Try/Catch with Code Node
Section titled “Strategy 2: Try/Catch with Code Node”Complex Error Handling ကို Code Node ဖြင့် ပြုလုပ်သည်:
// Code Node — Try/Catch Patterntry { const items = $input.all(); const results = [];
for (const item of items) { try { // Risky operation const processed = await processItem(item.json); results.push({ json: { ...processed, status: 'success' } }); } catch (itemError) { // Item-level error — log but continue results.push({ json: { ...item.json, status: 'failed', error: itemError.message } }); } }
return results;
} catch (fatalError) { // Workflow-level fatal error throw new Error(`Fatal: ${fatalError.message}`);}Strategy 3: Retry Logic
Section titled “Strategy 3: Retry Logic”API Rate Limit သို့မဟုတ် Temporary Error တွေအတွက် Retry:
Exponential Backoff Retry — 30s → 2min → Slack Alert
// Retry with Exponential Backoff (Code Node)async function withRetry(fn, maxRetries = 3) { let lastError;
for (let i = 0; i < maxRetries; i++) { try { return await fn(); } catch (error) { lastError = error; const delay = Math.pow(2, i) * 1000; // 1s, 2s, 4s await new Promise(resolve => setTimeout(resolve, delay)); } }
throw lastError;}Error Workflow (Global Error Handler)
Section titled “Error Workflow (Global Error Handler)”n8n မှ Error Workflow Feature ဖြင့် မည်သည့် Workflow Error ဖြစ်ဆိုသည်ကို Auto-send ဖြင့် Notification ပေးနိုင်သည်:
Main Workflows ──▶ Any Error ──▶ Error Workflow (runs automatically)Error Workflow ဖန်တီးနည်း
Section titled “Error Workflow ဖန်တီးနည်း”- New Workflow ဖန်တီးပြီး “n8n Trigger” → “Workflow Error” ကို ရွေးပါ
- Error details ကို Slack / Email ဖြင့် Alert ပေးပါ
Global Error Workflow — Error တိုင်း Auto-notify ပေးသည်
Error Trigger မှ ရရှိသော Data
Section titled “Error Trigger မှ ရရှိသော Data”{ "execution": { "id": "12345", "url": "https://n8n.example.com/workflow/runs/12345", "retryOf": null, "error": { "message": "Could not get parameter 'url'", "stack": "NodeOperationError: ..." }, "lastNodeExecuted": "HTTP Request", "mode": "trigger", "workflowId": "67890", "workflowName": "Order Processing" }}Slack Alert Template:
🚨 *Workflow Failed!*
Workflow: {{ $json.execution.workflowName }}Error: {{ $json.execution.error.message }}Node: {{ $json.execution.lastNodeExecuted }}Time: {{ $now.toISO() }}
🔗 <{{ $json.execution.url }}|View Execution>Global Error Workflow ကို Register လုပ်နည်း
Section titled “Global Error Workflow ကို Register လုပ်နည်း”Settings → “Workflow Settings” → “Error Workflow” → ဖန်တီးထားသော Error Workflow ကို ရွေးပါ
Workflow Settings:
- Error Workflow: [My Error Handler Workflow]
- Timezone: [Asia/Yangon]
- Save Execution: [Always]
Data Validation
Section titled “Data Validation”API ကိုမပို့မီ Data ကို Validate လုပ်ခြင်း:
// Code Node — Validation Gateconst items = $input.all();const valid = [];const invalid = [];
for (const item of items) { const { name, email, amount } = item.json; const errors = [];
if (!name || name.trim() === '') errors.push('Name is required'); if (!email || !email.includes('@')) errors.push('Invalid email'); if (!amount || amount <= 0) errors.push('Amount must be positive');
if (errors.length > 0) { invalid.push({ json: { ...item.json, validationErrors: errors } }); } else { valid.push(item); }}
// Return valid items only (invalid goes to error log)if (invalid.length > 0) { console.log('Invalid items:', JSON.stringify(invalid));}
return valid;Execution Monitoring
Section titled “Execution Monitoring”n8n Dashboard မှ Execution History ကို Monitor လုပ်နိုင်သည်:
| Status | Workflow | Time | Duration |
|---|---|---|---|
| ✅ OK | Order Processing | 09:00 | 1.2s |
| ✅ OK | Daily Report | 09:01 | 3.4s |
| ❌ ERR | Gmail → Slack | 09:02 | 0.5s |
| ✅ OK | Order Processing | 09:03 | 1.1s |
Failed Execution ကို Click ဖြင့် Node-by-node Input/Output ကို ကြည့်ပြီး Debug နိုင်သည်။
နောက်သင်ခန်းစာမှာ Sub-Workflows — Workflow ကြီးများကို Modular ဖြင့် ဖန်တီးနည်း လေ့လာမည်!