Agent Skills
› AjayIrkal23/agentic-mercy-10x
› backend-error-handling
backend-error-handling
GitHub规范后端错误处理,定义错误分类、统一响应信封及HTTP状态码映射。确保日志安全脱敏,隐藏内部细节,实现服务层与控制器层的职责分离。
触发场景
定义后端错误类或分类体系
设计集中式错误处理器
审查日志记录与安全脱敏行为
将领域错误映射为HTTP状态码
安装
npx skills add AjayIrkal23/agentic-mercy-10x --skill backend-error-handling -g -y
SKILL.md
Frontmatter
{
"name": "backend-error-handling",
"schema": 1,
"category": "backend",
"surfaces": [
"backend"
],
"triggers": {
"paths": [],
"intents": [
"backend"
],
"keywords": [
"backend",
"behavior",
"centralized",
"client-safe",
"defining",
"error",
"handler",
"handling",
"logging",
"mapping",
"redaction",
"safe",
"taxonomy"
]
},
"platforms": [
"linux",
"darwin",
"windows"
],
"token-cost": 482,
"description": "ALWAYS invoke when defining backend error taxonomy, centralized handler behavior, safe logging, redaction, or client-safe error mapping.",
"disable-model-invocation": false
}
Backend Error Handling
Overview
Backend failures must be structured, safe, and predictable.
This skill owns the error taxonomy, centralized handler behavior, and the rule that clients never see raw internal failures.
Use When
- Defining or reviewing backend error classes.
- Mapping domain errors to HTTP status codes.
- Designing centralized error handling.
- Reviewing safe logging and redaction behavior.
Do Not Use
- Service/controller boundary questions by themselves.
- API query semantics by themselves.
- Performance tuning without error-handling impact.
Standard Error Envelope
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Safe user-facing message",
"details": {}
}
}
Rules:
successmust befalseerror.codeis requiredmessagemust be safe for clientsdetailsis optional and should stay narrow
Status Code Rules
400validation401unauthorized403forbidden404not found409conflict429rate limited500internal error
Centralized Handler Rules
- Normalize internal errors into the public error envelope.
- Log safely.
- Hide stack traces and internal implementation details from clients.
- Keep controllers from building ad hoc error payloads unless they are only delegating to a shared formatter.
Service Rules
- Services throw typed domain errors.
- Services do not send transport responses.
- Services do not swallow failures silently.
Logging Rules
- Log enough context to debug.
- Do not log secrets, tokens, or sensitive payloads carelessly.
- Redact internal details before anything can surface to clients.
Combine With
api-contract-standardsfor envelope compatibility.service-layer-standardsfor where errors should originate.
References
- Use
references/full-guide.mdfor the longer strict version with class patterns and more detailed rules.
版本历史
- 581d130 当前 2026-07-19 09:04


