Write an Architecture Decision Record (ADR) document for a technical decision. Use when documenting a technical choice, architectural decision, or design decision.
日本語の概要は準備中です。原文の説明を表示しています。
Error handling patterns for API endpoints. Use when implementing error handling, writing middleware, or reviewing how errors are caught and formatted in API code.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
These patterns apply to all API endpoint handlers in this codebase. Every error must be handled explicitly — no unhandled exceptions may reach the HTTP framework.
All errors are caught and formatted at the handler level (or in a central error-handling middleware/decorator that wraps every handler). The framework never renders an unhandled exception as a response.
Use the shared error-handling decorator or middleware for every handler. Do not write try/catch blocks that format HTTP responses directly inside business logic. The pattern:
request → auth middleware → handler → error middleware → formatted response
If the handler throws, the error middleware intercepts it, logs it if appropriate, and converts it to the standard error envelope before sending the response.
Log 5xx errors (unexpected server errors) at the ERROR level with:
X-Request-ID header, or generate one if absent)Do not log 4xx errors at ERROR level. Log them at DEBUG level if useful for debugging, but 4xx errors are expected client behavior and should not generate noise in error monitoring.
Never log request bodies or response bodies unless explicitly enabled for debugging in a non-production environment.
Never include in an API error response:
Always include:
code in SCREAMING_SNAKE_CASEmessage safe for end usersUse 422 when the request is syntactically valid but semantically invalid (missing required fields, wrong value format, business rule violation detectable before touching external state).
{
"error": {
"code": "VALIDATION_FAILED",
"message": "One or more fields failed validation.",
"details": {
"fields": [
{ "field": "email", "message": "Must be a valid email address." }
]
}
}
}
Use 401 when the request has no token, the token is expired, or the token is invalid. The message should not indicate which of these conditions applies — treat them identically to avoid enumeration attacks.
{
"error": {
"code": "UNAUTHENTICATED",
"message": "Authentication is required to access this resource."
}
}
Use 403 when the user is authenticated but does not have permission to perform the action. Use a consistent message that does not reveal whether the resource exists.
{
"error": {
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action."
}
}
Use 404 when a resource addressed by ID does not exist or has been deleted. If the user does not have permission to know whether the resource exists, return 403 instead of 404.
{
"error": {
"code": "NOT_FOUND",
"message": "The requested resource was not found."
}
}
{
"error": {
"code": "CONFLICT",
"message": "A user with this email address already exists."
}
}
Use 503 when a downstream dependency (database, external API) times out. Include a Retry-After header with a suggested retry delay in seconds.
{
"error": {
"code": "SERVICE_UNAVAILABLE",
"message": "The service is temporarily unavailable. Please try again shortly."
}
}
Response header: Retry-After: 30
Use 429 when the client has exceeded the rate limit. Include Retry-After and X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset headers.
{
"error": {
"code": "RATE_LIMITED",
"message": "Too many requests. Please slow down."
}
}
All other unhandled exceptions become 500. The response body contains only a generic message. The real error is logged internally.
{
"error": {
"code": "INTERNAL_ERROR",
"message": "An unexpected error occurred. If this persists, contact support."
}
}
An internal alert must fire for every 500 response in production. Do not let 500 errors go undetected.
| Code | Status | Meaning |
|---|---|---|
VALIDATION_FAILED | 422 | One or more input fields failed validation |
UNAUTHENTICATED | 401 | Missing or invalid authentication token |
FORBIDDEN | 403 | Authenticated but not authorized |
NOT_FOUND | 404 | Resource does not exist |
CONFLICT | 409 | Resource already exists or state conflict |
RATE_LIMITED | 429 | Client exceeded rate limit |
SERVICE_UNAVAILABLE | 503 | Downstream timeout or unavailability |
INTERNAL_ERROR | 500 | Unexpected server error |
Use these codes consistently. Do not create one-off codes for situations already covered here.
まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Write an Architecture Decision Record (ADR) document for a technical decision. Use when documenting a technical choice, architectural decision, or design decision.
日本語の概要は準備中です。原文の説明を表示しています。
REST API design conventions for this codebase. Use when writing or reviewing API endpoints, route definitions, response formatting, or client code that calls the API.
日本語の概要は準備中です。原文の説明を表示しています。
Automatically format code files after every edit using Prettier and ESLint. Active in the background whenever Claude edits a file. Formatting is silent — no prompts, no output unless a formatter fails. Use when you want consistent formatting enforced automatically during a coding session.
日本語の概要は準備中です。原文の説明を表示しています。
Create a git branch named after a GitHub issue.
日本語の概要は準備中です。原文の説明を表示しています。
Draft the changelog entry for all unreleased commits in Keep a Changelog format. Groups commits into Added, Changed, Fixed, Removed, and Security. Use before releasing a new version or when updating CHANGELOG.md.
日本語の概要は準備中です。原文の説明を表示しています。
Draft a CHANGELOG.md entry for the current changes in Keep a Changelog format. Use when releasing, tagging a version, or updating CHANGELOG.md.
日本語の概要は準備中です。原文の説明を表示しています。