Next.js Error Handling
Installation
SKILL.md
Next.js Error Handling
Expert guidance on handling expected errors and uncaught exceptions in Next.js App Router using error boundaries, notFound, useActionState, and catchError.
@doc-version: 16.2.6
Core Concepts
Errors แบ่งเป็น 2 ประเภท:
- Expected errors — เกิดขึ้นได้ปกติ (validation fail, request fail) → จัดการด้วย return values
- Uncaught exceptions — bugs ที่ไม่คาดคิด → จัดการด้วย error boundaries
Guidelines
1. Expected Errors — Server Functions
ใช้ useActionState จัดการ error จาก Server Actions — อย่าใช้ try/catch + throw แต่ให้ return error เป็น value: