Error Handling
The Tokencraft API uses conventional HTTP status codes to indicate success or failure of requests. All error responses include a JSON body with anerror field describing the problem.
Error Response Format
Status Codes
2xx Success
| Code | Description |
|---|---|
200 | OK - Request succeeded |
201 | Created - Resource created successfully |
4xx Client Errors
| Code | Description |
|---|---|
400 | Bad Request - Invalid input or parameters |
401 | Unauthorized - Missing or invalid authentication |
403 | Forbidden - Valid auth but insufficient permissions |
404 | Not Found - Resource doesn’t exist |
429 | Too Many Requests - Rate limit exceeded |
5xx Server Errors
| Code | Description |
|---|---|
500 | Internal Server Error - Something went wrong on our end |
503 | Service Unavailable - Temporary outage |
Common Errors
401 Unauthorized
Cause: Missing or invalid API token- Verify your token is correct
- Check the Authorization header format:
Bearer dtk_xxx - Ensure the token hasn’t been revoked
- Generate a new token if necessary
404 Not Found
Cause: Resource doesn’t exist or you don’t have access- Verify the resource ID is correct
- Ensure you own the resource
- Check for typos in the endpoint URL
400 Bad Request
Cause: Invalid input data- Check required fields are provided
- Validate input format matches API expectations
- Review the endpoint documentation
429 Rate Limit Exceeded
Cause: Too many requests in a short time- Wait 60 seconds before retrying
- Implement exponential backoff
- Reduce request frequency
- Cache API responses
500 Internal Server Error
Cause: Server-side error- Retry the request after a short delay
- Check status page for outages
- Contact support if the issue persists
Error Handling Examples
JavaScript/TypeScript
Python
With Retry Logic
Validation Errors
When creating or updating resources, validation errors provide specific field information:Best Practices
1. Always Check Response Status
2. Implement Retry Logic
For rate limits and server errors:3. Log Errors Appropriately
4. Provide User-Friendly Messages
Debugging Tips
1. Use Verbose Logging
2. Check Request Format
Ensure:- Authorization header is present and correct
- Content-Type header is set for POST/PATCH
- Request body is valid JSON
- URL is properly formatted
3. Validate Token
Test your token with a simple request:4. Check Rate Limit Headers
Response headers include rate limit info:Getting Help
If you encounter persistent errors:- Check the documentation
- Review your request format and authentication
- Check for service status updates
- Contact support with:
- Request details (endpoint, method, headers)
- Response status and error message
- Timestamp of the request
- Your API token ID (not the full token)