Skip to content

Artifact Sesi 4 | Production-ready dengan error handling + Code node


📋 Workflow Spec

Name: Production Order Processor v3
Pattern: Trigger → Transform → Route → Notify (with error handling)

[Webhook: New Order]


[Code Node: Normalize Data]


[Sheets: Lookup Customer] ← retry: 3, continue on fail: true


[Switch: Route by Tier]
    ├── "VIP"     → [Priority Path]
    │                 → [Slack: Urgent Alert]
    │                 → [Sheets: Priority Log]
    ├── "Regular" → [Normal Path]
    │                 → [Email: Order Notification]
    └── (fallback)→ [Default Path]
                      → [Email: General Notification]

[Error Workflow] (connected)
    → [Slack: #workflow-errors]
    → [Sheets: Error Log]

Code Node: Normalize Data

javascript
const raw = $input.item.json;

// Normalize phone
let phone = (raw.phone || '').replace(/\D/g, '');
if (phone.startsWith('0')) phone = '62' + phone.substring(1);

// Normalize tier
const tier = (raw.tier || 'regular').toLowerCase().trim();

// Validate amount
const amount = Number(raw.amount) || 0;

// Generate order ID
const orderId = 'ORD-' + Date.now();

return {
  json: {
    orderId,
    nama: raw.nama || 'Unknown',
    email: raw.email || '',
    phone_formatted: phone,
    tier,
    amount,
    product: raw.product || '',
    source: raw.source || 'unknown',
    timestamp: new Date().toISOString()
  }
};

Error Handling Config

Per-Node Settings

NodeRetryContinue on FailFallback
Sheets Lookup3x, 1s gapYesUse empty data
Slack Notif2x, 2s gapNo
Email Send2x, 2s gapYesLog to Sheets

Error Workflow

Name: Error Handler
[Error Trigger] → [Set: Format Error] → [Slack: #errors]
Error message template:
"❌ [\{{ $json.workflow.name }}] \{{ $json.node.name }}: \{{ $json.error.message }}"

Checklist

  • [ ] Code Node normalize data dengan benar
  • [ ] Switch node meroute berdasarkan tier
  • [ ] Fallback path ada
  • [ ] Retry configured di critical nodes
  • [ ] Error workflow terhubung
  • [ ] Logging aktif (Sheets/Slack)
  • [ ] Test dengan data valid, invalid, dan empty

Bootcamp AI Automation — akala.id