Communitygithub.com

YepAPI/错误处理

结构化错误类型、React 错误边界以及优雅降级处理。

错误处理 是什么?

此技能提供了一套全面的错误处理方案,适用于 Web 应用程序和 API 开发。它定义了结构化错误类型,例如带有 `code` 和 `statusCode` 属性的 `AppError` 类,便于在代码中统一处理错误。对于 React 前端,该技能强制使用错误边界进行崩溃恢复,当组件崩溃时会显示友好的备选 UI,同时记录错误详情以便调试。它还强调优雅降级:当某个功能失败时,应用会显示一条用户友好的消息(例如“出了问题”),而不会崩溃或暴露堆栈跟踪。此外,该技能包含了在记录错误时附加上下文(用户 ID、请求 ID、时间戳、错误代码)的规则,对网络错误(502、429)进行带指数退避的重试(最多 3 次),在验证失败时快速失败(立即返回 400 状态码),并且严格禁止使用空的 `catch` 块吞没错误——至少必须记录错误。

兼容平台~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.

相关技能