Skip to content
GitHub

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 မပြည့်စုံမည်။

Node တစ်ခုသာ Fail ဖြစ်ပြီး Workflow ရပ်တန့်သည်:

Trigger
HTTP Request ❌ Connection timed out
Slack မရောက်တော့ပါ

HTTP Request Fail ဖြစ်ရင် နောက် Node တွေ မပြေးတော့ပါ

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)

Node တစ်ခု Fail ဖြစ်ရင် Alternative Path တစ်ခု Run သည်:

HTTP Request
Success ဖြစ်သလား?
SUCCESS ✅
Process Data
ERROR ❌
Log Error
Slack: Alert

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)

Complex Error Handling ကို Code Node ဖြင့် ပြုလုပ်သည်:

// Code Node — Try/Catch Pattern
try {
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}`);
}

API Rate Limit သို့မဟုတ် Temporary Error တွေအတွက် Retry:

HTTP Request
Wait: 30s ❌ Failed
Retry HTTP Request
Wait: 2 min ❌ Failed again
Final Retry
Slack: Critical Alert ❌ Still failing

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;
}

n8n မှ Error Workflow Feature ဖြင့် မည်သည့် Workflow Error ဖြစ်ဆိုသည်ကို Auto-send ဖြင့် Notification ပေးနိုင်သည်:

Main Workflows ──▶ Any Error ──▶ Error Workflow (runs automatically)

Error Workflow ဖန်တီးနည်း

Section titled “Error Workflow ဖန်တီးနည်း”
  1. New Workflow ဖန်တီးပြီး “n8n Trigger”“Workflow Error” ကို ရွေးပါ
  2. Error details ကို Slack / Email ဖြင့် Alert ပေးပါ

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]

API ကိုမပို့မီ Data ကို Validate လုပ်ခြင်း:

// Code Node — Validation Gate
const 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;

n8n Dashboard မှ Execution History ကို Monitor လုပ်နိုင်သည်:

StatusWorkflowTimeDuration
✅ OKOrder Processing09:001.2s
✅ OKDaily Report09:013.4s
❌ ERRGmail → Slack09:020.5s
✅ OKOrder Processing09:031.1s

Failed Execution ကို Click ဖြင့် Node-by-node Input/Output ကို ကြည့်ပြီး Debug နိုင်သည်။

နောက်သင်ခန်းစာမှာ Sub-Workflows — Workflow ကြီးများကို Modular ဖြင့် ဖန်တီးနည်း လေ့လာမည်!