<< All versions

Skill v1.0.0

currentAutomated scan100/100
revfactory/harness-100/api-error-design
──Details
PublishedOctober 14, 2026 at 11:28 PM
Content Hashsha256:ab71f7006a3179d4...
Git SHA8e8d35c6a191
──Files
Files (1 file, 6.2 KB)
SKILL.md6.2 KBactive
SKILL.md · 177 lines · 6.2 KB

version: "1.0.0" name: api-error-design description: "API error design patterns. An extension skill for doc-writer/mock-tester that provides error code systems, error response structures, client-friendly error messages, error catalog construction, and retry/fallback strategies. Use when designing API error handling systems involving 'API error design', 'error codes', 'error responses', 'error catalogs', 'error messages', 'retry strategies', etc. Note: actual error handling code implementation is outside the scope of this skill."


API Error Design — API Error Design Patterns

A reference for error systems, message design, and recovery strategies used by the doc-writer and mock-tester agents when designing API error documentation and tests.

Target Agents

  • doc-writer — Applied when writing error reference documentation
  • mock-tester — Applied when designing error scenario tests

Error Code System Design

Hierarchical Error Code Structure

{DOMAIN}_{CATEGORY}_{DETAIL}
Examples:
AUTH_TOKEN_EXPIRED -- Authentication > Token > Expired
ORDER_PAYMENT_DECLINED -- Order > Payment > Declined
USER_VALIDATION_EMAIL -- User > Validation > Email

Error Code Catalog by Domain

Authentication/Authorization (AUTH)

CodeHTTPMessageClient Action
AUTH_REQUIRED401Authentication is requiredRedirect to login page
AUTH_TOKEN_EXPIRED401Token has expiredAttempt token refresh
AUTH_TOKEN_INVALID401Invalid tokenRe-authenticate
AUTH_FORBIDDEN403You do not have permission for this actionGuide user to request permissions
AUTH_ACCOUNT_LOCKED403Account is locked. Please retry after 15 minutesDisplay wait timer
AUTH_INVALID_CREDENTIALS401Invalid email or passwordPrompt re-entry

Validation (VALIDATION)

CodeHTTPMessageField-Level Detail
VALIDATION_REQUIRED422Required field is missingThe {field} field is required
VALIDATION_FORMAT422Invalid formatPlease enter a valid {type}
VALIDATION_RANGE422Value is out of rangePlease enter a value between {min} and {max}
VALIDATION_UNIQUE409Value is already in useThis {field} is already registered
VALIDATION_LENGTH422Length limit exceededPlease enter no more than {max} characters

Resource (RESOURCE)

CodeHTTPMessage
RESOURCE_NOT_FOUND404The requested resource was not found
RESOURCE_ALREADY_EXISTS409Resource already exists
RESOURCE_DELETED410Resource has been deleted
RESOURCE_LOCKED423Resource is locked

Rate Limit

CodeHTTPMessage
RATE_LIMIT_EXCEEDED429Request limit exceeded. Please retry after {retryAfter} seconds

Server (SERVER)

CodeHTTPMessage
SERVER_INTERNAL500A server error occurred. Please retry shortly
SERVER_MAINTENANCE503Service is under maintenance
SERVER_UPSTREAM502Failed to connect to an external service

Error Response Structure Standard

Basic Structure

json
{
"error": {
"code": "AUTH_TOKEN_EXPIRED",
"message": "Token has expired",
"detail": "The access token has expired. Please refresh using your refresh token.",
"timestamp": "2025-03-15T09:30:00Z",
"requestId": "req_abc123def456",
"path": "/api/v1/users/me"
}
}

Validation Error (Per-Field)

json
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Input values are invalid",
"errors": [
{
"field": "email",
"code": "VALIDATION_FORMAT",
"message": "Please enter a valid email address",
"value": "invalid-email"
},
{
"field": "password",
"code": "VALIDATION_LENGTH",
"message": "Password must be at least 8 characters",
"constraint": { "min": 8 }
}
]
}
}

Error Message Writing Principles

Three Elements of a Good Error Message

  1. What went wrong — Describe the problem
  2. Why it went wrong — Explain the cause or constraint
  3. How to fix it — Provide a specific action

Do / Don't

Don'tDo
"Error occurred""Failed to create the order"
"Invalid input""Price must be a number greater than 0"
"Server error: NullPointerException at...""A server error occurred. Please retry shortly"
"Access denied""You do not have permission to modify this order. Please contact an administrator"
"Duplicate key constraint violation""This email is already registered"

Multilingual Error Message Structure

json
{
"error": {
"code": "VALIDATION_REQUIRED",
"message": "Required field is missing",
"messageKey": "error.validation.required",
"params": { "field": "email" }
}
}

Retry/Fallback Strategy

Retry Eligibility

HTTP StatusRetryable?Strategy
408YesRetry immediately
429YesWait per Retry-After header
500Yes (conditional)Exponential backoff
502, 503, 504YesExponential backoff
400, 401, 403, 404NoClient-side fix required
409, 422NoInput correction required

Exponential Backoff

wait_time = min(baseDelay * 2^attempt + jitter, maxDelay)
Example: baseDelay=1s, maxDelay=30s
Attempt 1: 1s + random(0~500ms)
Attempt 2: 2s + random(0~500ms)
Attempt 3: 4s + random(0~500ms)
Attempt 4: 8s + random(0~500ms)
Maximum 3-5 attempts

Error Test Scenario Matrix

CategoryTest CaseExpected Code
No authenticationRequest without Authorization header401
Expired tokenRequest with expired JWT401
No permissionAccess another user's resource403
Non-existent IDQuery with random UUID404
Missing required fieldRemove required field from body422
Invalid format"abc" in email field422
Duplicate creationPOST same data twice409
Bulk requestsExceed Rate Limit429
Malformed JSONSend {invalid json400
Empty bodyContent-Length: 0400
All versions