Error Handling Reference
This reference covers error responses, status codes, and troubleshooting in the FG API platform.
HTTP Status Codes
Success Codes
200 OK
Description: Request successful
Usage: GET, PUT requests
Example: Successfully retrieved endpoint data
201 Created
Description: Resource created successfully
Usage: POST requests
Example: New endpoint or field created
Client Error Codes
400 Bad Request
Description: Invalid request data
Common causes: Missing required fields, invalid data types, validation errors
Example: Missing required field in API request
401 Unauthorized
Description: Authentication required or failed
Common causes: Missing token, invalid token, expired token
Example: Accessing protected endpoint without authentication
403 Forbidden
Description: Access denied
Common causes: Account pending approval, insufficient permissions
Example: Trying to access features with pending account
404 Not Found
Description: Resource not found
Common causes: Invalid endpoint ID, non-existent field
Example: Requesting endpoint that doesn't exist
409 Conflict
Description: Resource conflict
Common causes: Duplicate entries, name conflicts
Example: Creating endpoint with existing name
429 Too Many Requests
Description: Rate limit exceeded
Common causes: Too many requests in time window
Example: Exceeding authentication rate limit
Server Error Codes
500 Internal Server Error
Description: Server-side error
Common causes: Database errors, unexpected server issues
Example: Database connection failure
Error Response Format
Standard Error Response
{
"error": "Error message description",
"details": "Additional error details (optional)"
}Authentication Error Response
{
"error": "Authentication error message",
"tokenExpired": true
}Rate Limiting Error Response
{
"error": "Too many requests, please try again later",
"retryAfter": "15 minutes"
}Common Error Scenarios
Authentication Errors
Missing Token
Status: 401 Unauthorized
{
"error": "token missing"
}Solution: Include Authorization header with Bearer token
Invalid Token
Status: 401 Unauthorized
{
"error": "token invalid"
}Solution: Check token format and validity
Expired Token
Status: 401 Unauthorized
{
"tokenExpired": true,
"error": "token expired"
}Solution: Use refresh token to get new access token
Account Pending Approval
Status: 403 Forbidden
{
"error": "account pending approval"
}Solution: Wait for administrator approval
Validation Errors
Missing Required Field
Status: 400 Bad Request
{
"error": "validation failed",
"details": "Field 'name' is required"
}Solution: Include all required fields in request
Invalid Data Type
Status: 400 Bad Request
{
"error": "validation failed",
"details": "Field 'age' must be a number"
}Solution: Ensure data types match field configuration
Invalid Field Value
Status: 400 Bad Request
{
"error": "validation failed",
"details": "Field 'category' must be one of: General, Support, Sales"
}Solution: Use valid values for select fields
Resource Errors
Endpoint Not Found
Status: 404 Not Found
{
"error": "Endpoint not found"
}Solution: Check endpoint ID and ensure endpoint exists
Field Not Found
Status: 404 Not Found
{
"error": "Field not found"
}Solution: Check field ID and ensure field exists
Duplicate Entry
Status: 409 Conflict
{
"error": "duplicate entry",
"details": "A record with this information already exists"
}Solution: Use unique values or update existing record
Rate Limiting Errors
Authentication Rate Limit
Status: 429 Too Many Requests
{
"error": "Too many authentication attempts, please try again later",
"retryAfter": "15 minutes"
}Solution: Wait 15 minutes before trying again
API Rate Limit
Status: 429 Too Many Requests
{
"error": "Too many requests, please try again later",
"retryAfter": "15 minutes"
}Solution: Reduce request frequency or wait for rate limit reset
Error Handling Best Practices
Client-Side Error Handling
Check Response Status
const response = await fetch('/api/endpoints', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
const errorData = await response.json();
switch (response.status) {
case 401:
if (errorData.tokenExpired) {
// Handle token expiration
await refreshToken();
} else {
// Handle other auth errors
redirectToLogin();
}
break;
case 400:
// Handle validation errors
showValidationErrors(errorData.details);
break;
case 429:
// Handle rate limiting
showRateLimitMessage(errorData.retryAfter);
break;
default:
// Handle other errors
showGenericError(errorData.error);
}
}Automatic Token Refresh
async function makeAuthenticatedRequest(url, options = {}) {
const userData = JSON.parse(localStorage.getItem('user'));
const accessToken = userData.accessToken;
const response = await fetch(url, {
...options,
headers: {
...options.headers,
'Authorization': `Bearer ${accessToken}`
}
});
if (response.status === 401) {
const errorData = await response.json();
if (errorData.tokenExpired) {
// Try to refresh token
const refreshSuccess = await refreshToken();
if (refreshSuccess) {
// Retry original request
return makeAuthenticatedRequest(url, options);
} else {
// Refresh failed, redirect to login
redirectToLogin();
return;
}
}
}
return response;
}Server-Side Error Handling
Proper Error Responses
// Validation error
if (!name) {
return response.status(400).json({
error: "validation failed",
details: "Name is required"
});
}
// Authentication error
if (!user) {
return response.status(401).json({
error: "authentication required"
});
}
// Not found error
if (!endpoint) {
return response.status(404).json({
error: "Endpoint not found"
});
}Troubleshooting Guide
Common Issues and Solutions
"Token missing" Error
Problem: API request without authentication Solution: Include Authorization header with Bearer token
"Token expired" Error
Problem: Access token has expired Solution: Use refresh token to get new access token
"Account pending approval" Error
Problem: Account not yet approved by administrator Solution: Wait for approval or contact administrator
"Too many requests" Error
Problem: Exceeded rate limit Solution: Wait for rate limit reset or reduce request frequency
"Endpoint not found" Error
Problem: Invalid endpoint ID or endpoint doesn't exist Solution: Check endpoint ID and ensure endpoint exists
"Field not found" Error
Problem: Invalid field ID or field doesn't exist Solution: Check field ID and ensure field exists
"Validation failed" Error
Problem: Invalid request data Solution: Check required fields and data types
Debugging Tips
Check Request Format
// Ensure proper headers
const headers = {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
};
// Ensure proper request body
const body = JSON.stringify({
name: 'John Doe',
email: 'john@example.com'
});Verify Field Configuration
// Check field requirements
const fieldConfig = {
name: { required: true, type: 'string' },
email: { required: true, type: 'string' },
age: { required: false, type: 'number' }
};Monitor Rate Limits
// Check rate limit headers
const rateLimitRemaining = response.headers.get('X-RateLimit-Remaining');
const rateLimitReset = response.headers.get('X-RateLimit-Reset');
if (rateLimitRemaining === '0') {
console.log('Rate limit reached, reset at:', new Date(rateLimitReset * 1000));
}Error Monitoring
Client-Side Monitoring
// Log errors for debugging
function logError(error, context) {
console.error('API Error:', {
error: error.message,
status: error.status,
context: context,
timestamp: new Date().toISOString()
});
}
// Track error patterns
function trackErrorPattern(error) {
// Send to analytics service
analytics.track('api_error', {
error_type: error.type,
endpoint: error.endpoint,
user_id: getCurrentUserId()
});
}Server-Side Monitoring
// Log errors with context
logger.error('API Error:', {
error: error.message,
stack: error.stack,
request: {
method: request.method,
url: request.url,
user: request.user?.id
},
timestamp: new Date().toISOString()
});Getting Help
Error Documentation
Check this error handling reference
Review API endpoint documentation
Look at field configuration guides
Support Resources
Contact support through the platform
Check the FAQ for common issues
Join community discussions
Debugging Tools
Use browser developer tools
Check network requests and responses
Review server logs for detailed error information