$ loading_
提供 TypeScript、Python 与 Go 的健壮错误处理模式与用户提示策略
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "error-handling" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/error-handling/SKILL.md 2. 保存为 ~/.claude/skills/error-handling/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为 TypeScript、Python 和 Go 项目设计一套统一的错误处理规范,涵盖错误分类、typed errors、自定义异常、日志字段、用户可见报错文案,以及哪些错误应重试、降级或直接失败。
一份可落地的跨语言错误处理规范,包含分类原则、代码模式和用户提示建议。
我有一个会调用第三方支付接口的服务,请给出 TypeScript 或 Go 的错误处理方案,包含超时、重试退避、熔断器、幂等处理、监控告警,以及如何避免把底层错误直接暴露给用户。
一套面向生产环境的 API 容错方案,说明如何处理外部依赖失败并保护用户体验。
请帮我为前端应用设计错误边界与用户提示文案策略,区分网络错误、权限错误、表单校验错误和系统异常,并给出开发者日志记录内容与用户可操作的下一步建议。
一套前端错误边界与提示文案方案,兼顾技术可观测性和用户可理解性。
Consistent, robust error handling patterns for production applications.
catch block must either handle, re-throw, or log// Define an error hierarchy for your domain
export class AppError extends Error {
constructor(
message: string,
public readonly code: string,
public readonly statusCode: number = 500,
public readonly details?: unknown,
) {
super(message)
this.name = this.constructor.name
// Maintain correct prototype chain in transpiled ES5 JavaScript.
// Required for `instanceof` checks (e.g., `error instanceof NotFoundError`)
// to work correctly when extending the built-in Error class.
Object.setPrototypeOf(this, new.target.prototype)
}
}
export class NotFoundError extends AppError {
constructor(resource: string, id: string) {
super(`${resource} not found: ${id}`, 'NOT_FOUND', 404)
}
}
export class ValidationError extends AppError {
constructor(message: string, details: { field: string; message: string }[]) {
super(message, 'VALIDATION_ERROR', 422, details)
}
}
export class UnauthorizedError extends AppError {
constructor(reason = 'Authentication required') {
super(reason, 'UNAUTHORIZED', 401)
}
}
export class RateLimitError extends AppError {
constructor(public readonly retryAfterMs: number) {
super('Rate limit exceeded', 'RATE_LIMITED', 429)
}
}
For operations where failure is expected and common (parsing, external calls):
type Result<T, E = AppError> =
| { ok: true; value: T }
| { ok: false; error: E }
function ok<T>(value: T): Result<T> {
return { ok: true, value }
}
function err<E>(error: E): Result<never, E> {
return { ok: false, error }
}
// Usage
async function fetchUser(id: string): Promise<Result<User>> {
try {
const user = await db.users.findUnique({ where: { id } })
if (!user) return err(new NotFoundError('User', id))
return ok(user)
} catch (e) {
return err(new AppError('Database error', 'DB_ERROR'))
}
}
const result = await fetchUser('abc-123')
if (!result.ok) {
// TypeScript knows result.error here
logger.error('Failed to fetch user', { error: result.error })
return
}
// TypeScript knows result.value here
console.log(result.value.email)
import { NextRequest, NextResponse } from 'next/server'
function handleApiError(error: unknown): NextResponse {
// Known application error
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
message: error.message,
...(error.details ? { details: error.details } : {}),
},
},
{ status: error.statusCode },
)
}
// Zod validation error
if (error instanceof z.ZodError) {
return NextResponse.json(
{
error: {
code: 'VALIDATION_ERROR',
message: 'Request validation failed',
details: error.issues.map(i => ({
field: i.path.join('.'),
message: i.message,
})),
},
},
…
依据C++核心指南辅助编写、审查与重构更现代安全的C++代码。
帮助你设计与优化 Spring Boot 后端架构、接口与服务实现。
帮助开发者与设计师实现 iOS 液态玻璃动态界面与交互效果。
调用最新框架与库文档,快速回答配置、API与代码示例问题
帮助开发者使用 Bun 进行运行、打包、测试与依赖管理,并评估替代 Node 的时机。
用测试驱动开发流程编写新功能、修复缺陷并安全重构代码。
提供地道 Go 语言模式与最佳实践,帮助构建健壮高效且易维护的应用
帮助开发者掌握地道 Rust 模式、所有权、并发与错误处理实践
帮助开发者提取并核对 React 错误信息与错误码映射,排查未知错误码警告。
快速修复代码格式、Lint与常见错误,帮助提交前顺利通过 CI 检查
通过四个示例工具演示 MCP 服务的参数设计、结构化输出与错误处理
针对 Python、JS/TS 与 Go 提供安全最佳实践审查与改进建议