Communitygithub.com

YepAPI/skills

結構化錯誤處理、React 錯誤邊界與優雅降級。

skills 是什麼?

此技能專注於在前端與後端應用程式中實施強健的錯誤處理策略。它定義了結構化的錯誤類型(如具有 code 和 statusCode 屬性的 AppError),以便於標準化處理與錯誤碼對應。在 React 前端中,它利用錯誤邊界(Error Boundaries)攔截渲染錯誤,顯示友善的備用 UI 而非應用程式崩潰。技能也強調優雅降級:當某項功能失敗時,顯示一則使用者友善的訊息,而不讓整個應用程式當機。此外,它建議為異常記錄上下文(使用者 ID、請求 ID、時間戳記與錯誤碼),並對暫時性錯誤(網路問題、502、429)採用指數退避與最多 3 次重試的機制。此技能適用於任何使用 React 或通用 JavaScript/TypeScript 後端的開發環境,例如 Claude Code、Cursor 或 Codex。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/error-handling

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

錯誤處理

規則

  • 結構化錯誤類型:class AppError extends Error { code: string; statusCode: number }
  • 在 React 中使用錯誤邊界進行崩潰復原 — 顯示備用 UI,記錄錯誤
  • 優雅降級:功能失敗 → 顯示訊息,不讓應用程式崩潰
  • 使用者友善訊息:顯示「發生錯誤」,而非堆疊追蹤
  • 記錄錯誤並附上上下文:使用者 ID、請求 ID、時間戳記、錯誤碼
  • 對暫時性錯誤(網路問題、502、429)採用指數退避重試 — 最多 3 次重試
  • 驗證錯誤時快速失敗 — 立即回傳 400,不繼續處理
  • 絕不因空 catch 區塊而吞沒錯誤 — 至少應記錄它們

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相關技能