Error Handling
The BookWish API uses conventional HTTP status codes and returns detailed error information in JSON format to help you understand and resolve issues.
Error Response Format
All error responses follow a consistent structure:
{
"error": "ErrorCode",
"message": "Human-readable error description",
"details": []
}
| Field | Type | Description |
|---|---|---|
error | string | Machine-readable error code |
message | string | Human-readable error description |
details | array/object | Optional additional error information |
HTTP Status Codes
The API uses standard HTTP status codes to indicate the success or failure of requests:
Success Codes (2xx)
| Code | Status | Description |
|---|---|---|
| 200 | OK | Request succeeded |
| 201 | Created | Resource successfully created |
| 204 | No Content | Request succeeded with no response body |
Client Error Codes (4xx)
| Code | Status | Description |
|---|---|---|
| 400 | Bad Request | Invalid request format or missing required fields |
| 401 | Unauthorized | Missing or invalid authentication |
| 403 | Forbidden | Authenticated but not authorized for this action |
| 404 | Not Found | Resource does not exist |
| 409 | Conflict | Request conflicts with existing data |
| 422 | Unprocessable Entity | Request is well-formed but semantically invalid |
| 429 | Too Many Requests | Rate limit exceeded |
Server Error Codes (5xx)
| Code | Status | Description |
|---|---|---|
| 500 | Internal Server Error | Unexpected server error |
| 502 | Bad Gateway | Upstream service error |
| 503 | Service Unavailable | Service temporarily unavailable |
Error Categories
Authentication Errors (401)
Authentication failures when credentials or tokens are invalid:
Missing Authorization Header
{
"error": "Unauthorized",
"message": "Missing or invalid authorization header"
}
Cause: Request missing Authorization header or header not in Bearer {token} format.
Solution: Include valid Bearer token in Authorization header.
Invalid or Expired Token
{
"error": "Unauthorized",
"message": "Invalid or expired token"
}
Cause: JWT token is malformed, expired, or signed with wrong secret.
Solution: Refresh access token using refresh token endpoint.
User Not Found
{
"error": "Unauthorized",
"message": "User not found"
}
Cause: Token is valid but user account no longer exists.
Solution: User must re-authenticate or create new account.
Invalid Credentials
{
"error": "InvalidCredentials",
"message": "Invalid credentials"
}
Cause: Email or password incorrect during login.
Solution: Verify credentials and retry.
Token Revoked
{
"error": "InvalidToken",
"message": "Token is invalid or expired"
}
Cause: Refresh token has been revoked (user logged out).
Solution: User must log in again.
Validation Errors (400)
Input validation failures with detailed error information:
{
"error": "ValidationError",
"message": "Request validation failed",
"details": [
{
"path": "email",
"message": "Invalid email format"
},
{
"path": "password",
"message": "String must contain at least 8 character(s)"
}
]
}
Common Validation Rules:
| Field | Validation | Error Message |
|---|---|---|
| Valid email format | "Invalid email format" | |
| password | Minimum 8 characters | "String must contain at least 8 character(s)" |
| display_name | 1-100 characters | "String must contain at least 1 character(s)" |
| username | 3-50 chars, alphanumeric + underscore | "Username must contain only letters, numbers, and underscores" |
| bookId | Required | "bookId is required" |
| content | Max 1000 characters | "Content must be 1000 characters or less" |
Resource Not Found (404)
Requested resource does not exist:
{
"error": "NotFound",
"message": "User not found"
}
Common Not Found Errors:
| Resource | Error Message |
|---|---|
| User | "User not found" |
| Book | "Book not found" |
| Store | "Store not found" |
| Line | "Line not found" |
| Inventory Item | "Inventory item not found" |
| Order | "Order not found" |
| Club | "Club not found" |
| Challenge | "Challenge not found" |
Conflict Errors (409)
Request conflicts with existing data:
Email Already Exists
{
"error": "EmailConflict",
"message": "Email already in use"
}
Cause: Attempting to register with email that's already registered.
Solution: Use different email or log in with existing account.
Username Already Taken
{
"error": "UsernameConflict",
"message": "Username already taken"
}
Cause: Attempting to use username that's already taken.
Solution: Choose a different username.
Business Logic Errors (400, 403)
Errors related to business rules and permissions:
Not a Guest Account
{
"error": "BadRequest",
"message": "User is not a guest"
}
Cause: Attempting to migrate a full account as if it were a guest.
Solution: This action only applies to guest accounts.
Not Store Owner
{
"error": "Forbidden",
"message": "Only store owners can access this resource"
}
Cause: Attempting to access store management features without ownership.
Solution: User must own the store to perform this action.
Insufficient Permissions
{
"error": "Forbidden",
"message": "Insufficient permissions"
}
Cause: User tier does not allow this action.
Solution: Upgrade user tier or request appropriate permissions.
Rate Limiting Errors (429)
Rate limit exceeded errors come in two forms: