一键导入
error-handling
Design and implement standardized error handling patterns — consistent error
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Design and implement standardized error handling patterns — consistent error
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Consult and write the ARAYA postoffice — the operational-directive channel. Advisory, never a gate: read it at cycle start, append your entry at cycle end, consider its directives, never be blocked by it. Governance acts never travel the postoffice.
Audit and enforce brand compliance across all projects and platforms — logo,
Design REST and GraphQL APIs following OpenAPI 3.1 standards. Produce complete
Connect frontend to backend — type-safe API clients, request/response handling,
Implement authentication and authorization middleware — JWT validation, role-based
Design scalable component architectures — design systems, component libraries,
| name | error-handling |
| description | Design and implement standardized error handling patterns — consistent error |
| governance | Constitution ENG-004: Engineering Excellence & Software Craftsmanship Standard |
Design and implement standardized error handling patterns — consistent error responses, logging, and recovery — so errors are debuggable for developers and safe for users.
Inconsistent error handling leads to information leakage (stack traces to users), lost debugging context (no logs), and confusing API responses. This skill establishes a single error-handling pattern used by every endpoint and service.
At project setup. When an existing project has inconsistent error handling. When adding error tracking/monitoring. Before any API goes to production.
Project language, framework, logging setup, error tracking service.
// src/errors/AppError.ts
export class AppError extends Error {
constructor(
message: string,
public statusCode: number,
public code: string,
public details?: unknown
) {
super(message);
this.name = "AppError";
}
}
export class NotFoundError extends AppError {
constructor(resource: string, id: string) {
super(`${resource} not found`, 404, "NOT_FOUND", { resource, id });
}
}
export class ValidationError extends AppError {
constructor(details: Array<{ field: string; message: string }>) {
super("Validation failed", 400, "VALIDATION_ERROR", details);
}
}
export class UnauthorizedError extends AppError {
constructor(message = "Authentication required") {
super(message, 401, "UNAUTHORIZED");
}
}
export class ForbiddenError extends AppError {
constructor(message = "Insufficient permissions") {
super(message, 403, "FORBIDDEN");
}
}
export class ConflictError extends AppError {
constructor(resource: string) {
super(`${resource} already exists`, 409, "CONFLICT");
}
}
// src/middleware/errorHandler.ts
import { Request, Response, NextFunction } from "express";
import { AppError } from "../errors/AppError";
import { logger } from "../utils/logger";
export function errorHandler(
err: Error,
req: Request,
res: Response,
_next: NextFunction
): void {
// Known application errors
if (err instanceof AppError) {
logger.warn({
message: err.message,
code: err.code,
statusCode: err.statusCode,
path: req.path,
method: req.method,
});
res.status(err.statusCode).json({
error: err.code,
message: err.message,
...(err.details && { details: err.details }),
});
return;
}
// Unknown errors — log fully, return generic
logger.error({
message: err.message,
stack: err.stack,
path: req.path,
method: req.method,
requestId: req.headers["x-request-id"],
});
res.status(500).json({
error: "INTERNAL_ERROR",
message: "An unexpected error occurred",
});
}
{ error: code, message: string, details?: any }