Complete reference of all error codes that the API may return, including their meanings and solutions.
All error responses follow a consistent format:
{
"code": 400,
"message": "Bad Request",
"data": null,
"errors": [
{
"field": "email",
"message": "Invalid email format"
}
],
"timestamp": "2024-01-01T00:00:00Z",
"path": "/api/documents"
}
Status Code | Meaning | Description |
---|
200 | OK | Request successful |
201 | Created | Resource created successfully |
202 | Accepted | Request accepted, processing |
204 | No Content | Request successful, no content returned |
Status Code | Meaning | Common Causes | Solutions |
---|
400 | Bad Request | Invalid request parameters | Check request parameter format and required fields |
401 | Unauthorized | Unauthorized access | Check if API token is valid |
403 | Forbidden | Insufficient permissions | Confirm user permissions or contact administrator |
404 | Not Found | Resource not found | Check resource ID or path |
405 | Method Not Allowed | Request method not allowed | Use correct HTTP method |
409 | Conflict | Resource conflict | Check if resource already exists |
422 | Unprocessable Entity | Data validation failed | Check data format and validation rules |
429 | Too Many Requests | Rate limit exceeded | Reduce request frequency or wait |
Status Code | Meaning | Common Causes | Solutions |
---|
500 | Internal Server Error | Server internal error | Contact technical support |
502 | Bad Gateway | Gateway error | Retry later or contact technical support |
503 | Service Unavailable | Service unavailable | Retry later |
504 | Gateway Timeout | Gateway timeout | Retry later |
Error Code | Error Message | Description | Solution |
---|
1001 | User not found | Specified user ID does not exist | Check if user ID is correct |
1002 | Email already exists | Email already in use during registration | Use different email or recover password |
1003 | Invalid password | Login password incorrect | Check password or reset password |
1004 | User disabled | User account disabled by administrator | Contact administrator to enable |
1005 | Invalid email format | Email address format incorrect | Use correct email format |
1006 | Password too weak | Password does not meet security requirements | Use stronger password |
Error Code | Error Message | Description | Solution |
---|
2001 | Invalid token | API token format error or expired | Get new valid token |
2002 | Token expired | API token has exceeded validity period | Refresh token or re-login |
2003 | Insufficient permissions | Current user has insufficient permissions | Contact administrator for permission upgrade |
2004 | Too many login attempts | Too many login failures in short time | Wait and retry later |
2005 | Invalid verification code | Entered verification code incorrect | Get new verification code |
2006 | Verification code expired | Verification code has exceeded validity period | Get new verification code |
Error Code | Error Message | Description | Solution |
---|
3001 | Data not found | Requested data record does not exist | Check if data ID is correct |
3002 | Data already exists | Data being created already exists | Use update operation or check uniqueness |
3003 | Invalid data format | Submitted data format incorrect | Check data format and type |
3004 | Missing required field | Missing required fields | Provide all required fields |
3005 | Field length exceeded | Field value exceeds maximum length | Shorten field value length |
3006 | Data relationship error | Related data does not exist or invalid | Check validity of related data |
Error Code | Error Message | Description | Solution |
---|
4001 | System maintenance | System under maintenance | Wait for maintenance completion |
4002 | Service unavailable | Service temporarily unavailable | Retry later |
4003 | Request timeout | Request processing timeout | Retry later or optimize request |
4004 | Storage full | Server storage space insufficient | Contact technical support |
4005 | Configuration error | System configuration error | Contact technical support |
Error Code | Error Message | Description | Solution |
---|
5001 | Operation not allowed | Operation not allowed in current state | Check business state |
5002 | Insufficient balance | Account balance insufficient | Top up or check balance |
5003 | Insufficient inventory | Product inventory insufficient | Choose other products or wait for restock |
5004 | Invalid order status | Order status does not allow this operation | Check order status |
5005 | Time restriction | Operation exceeds time limit | Operate within allowed time |
async function handleAPIError(response) {
if (!response.ok) {
const errorData = await response.json();
switch (response.status) {
case 400:
console.error('Bad request:', errorData.message);
if (errorData.errors) {
errorData.errors.forEach(error => {
console.error(`Field ${error.field}: ${error.message}`);
});
}
break;
case 401:
console.error('Authentication failed:', errorData.message);
window.location.href = '/login';
break;
case 403:
console.error('Insufficient permissions:', errorData.message);
alert('You do not have permission to perform this action');
break;
case 404:
console.error('Resource not found:', errorData.message);
break;
case 429:
console.error('Too many requests:', errorData.message);
setTimeout(() => {
}, 5000);
break;
case 500:
console.error('Server error:', errorData.message);
alert('Server temporarily experiencing issues, please try again later');
break;
default:
console.error('Unknown error:', errorData.message);
}
throw new APIError(response.status, errorData.message, errorData);
}
return response.json();
}
class APIError extends Error {
constructor(status, message, data) {
super(message);
this.name = 'APIError';
this.status = status;
this.data = data;
}
}
import requests
from requests.exceptions import RequestException
class APIError(Exception):
def __init__(self, status_code, message, data=None):
self.status_code = status_code
self.message = message
self.data = data
super().__init__(self.message)
def handle_api_response(response):
"""Handle API response and errors"""
try:
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError:
error_data = response.json()
if response.status_code == 400:
print(f"Bad request: {error_data['message']}")
elif response.status_code == 401:
print(f"Authentication failed: {error_data['message']}")
elif response.status_code == 403:
print(f"Insufficient permissions: {error_data['message']}")
elif response.status_code == 404:
print(f"Resource not found: {error_data['message']}")
elif response.status_code == 429:
print(f"Too many requests: {error_data['message']}")
elif response.status_code >= 500:
print(f"Server error: {error_data['message']}")
raise APIError(
response.status_code,
error_data['message'],
error_data
)
except RequestException as e:
print(f"Network request failed: {e}")
raise
In development environment, you can request more detailed error information:
const response = await fetch('/api/documents', {
headers: {
'Authorization': 'Bearer ' + token,
'X-Debug': 'true'
}
});
function logError(error, context) {
const errorLog = {
timestamp: new Date().toISOString(),
error: {
status: error.status,
message: error.message,
data: error.data
},
context: context,
userAgent: navigator.userAgent,
url: window.location.href
};
console.error('API Error:', errorLog);
}
async function retryRequest(requestFn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await requestFn();
} catch (error) {
if (i === maxRetries - 1) throw error;
if ([400, 401, 403, 404].includes(error.status)) {
throw error;
}
const delay = Math.pow(2, i) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
If you encounter error codes not listed in this documentation or need technical support, please:
- Record complete error information
- Provide detailed request information (URL, parameters, headers, etc.)
- Contact us through the following channels:
- Technical support email: support@leafmove.com
- Online customer service: https://leafmove.com/support
- GitHub Issues: https://github.com/leafmove/autodoc/issues