{"success":true,"name":"design-error-tsx-and-not-found-tsx-per-next-js-section","description":"Handling errors or missing data pages in a Next.js app","category":"ai-brimind","path":"ai-brimind/design-error-tsx-and-not-found-tsx-per-next-js-section/SKILL.md","file":"SKILL.md","content":"---\nname: design-error-tsx-and-not-found-tsx-per-next-js-section\ndescription: \"Handling errors or missing data pages in a Next.js app\"\n---\n\n# Design error.tsx and not-found.tsx Per Next.js Section\n\n## When to use\nProject is Next.js App Router, and errors show a white screen or generic crash, or missing records render as broken pages instead of a proper 404.\n\n## Example request\nproduct id does not exist and the page renders empty fields → call notFound() so Next.js serves the real 404 with the right status code. — Missing data is a 404, not a blank page. | one error.tsx at the root catching everything → a failure in a small widget nukes the whole app UI; boundaries per section keep the rest alive. — Error blast radius. | wrapping every fetch in try/catch that returns null quietly → errors vanish and pages half-render with holes. — Swallowed errors. | error.tsx that says 'Something went wrong' with no reset → the built-in reset() prop lets users retry without a full reload. — Recoverable boundaries.\n\n## Instructions\nAct like a safety engineer who plans where failures land before they happen. For every Next.js App Router section: 1) Decide the blast radius: place error.tsx files so that a crash in one section (dashboard widget, comments block) shows a contained fallback there, while the navbar and the rest of the app stay usable. One root-level boundary means one bad query kills everything — say explicitly which sections deserve their own. 2) Treat 'record not found' as its own case, not an error: when a fetch returns nothing for an id, call the built-in notFound() so the not-found.tsx renders with a correct 404 status — never render a half-empty page or throw a generic error for missing data. 3) Do not swallow: avoid try/catch blocks that return null just to keep pages rendering — let real unexpected errors reach the boundary where they are visible and logged, and reserve catch for cases you genuinely handle. 4) Use the boundary's props: error.tsx receives error and reset — offer the retry, and log the error to your monitoring, because a boundary that only shows a sad face hides problems. 5) If you are unsure whether a case is 'expected missing data' vs 'real failure', classify it out loud first — the two have different pages and different status codes. Only ship a section once its 404 path and its crash path are both designed, and explain why each boundary sits where it does — not just that the white screen is gone.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #504\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}