Skip to main content

Error Codes

Common Error Codes (All APIs)

CodeDescriptionResolution
AUTHENTICATION_FAILEDInvalid or missing API key/tokenCheck authentication headers
AUTHORIZATION_DENIEDInsufficient permissionsVerify user permissions
VALIDATION_ERRORInvalid request parametersCheck request format and required fields
RATE_LIMIT_EXCEEDEDToo many requestsImplement rate limiting and retry logic
INTERNAL_ERRORServer-side errorRetry request or contact support
NETWORK_TIMEOUTRequest timeoutImplement retry with exponential backoff

Datastore-Specific Errors

CodeDescriptionResolution
COLLECTION_NOT_FOUNDCollection doesn't existVerify collection name
DOCUMENT_NOT_FOUNDDocument doesn't existCheck document key
INVALID_QUERYMalformed QLO queryValidate query syntax
DUPLICATE_KEYDocument key already existsUse unique keys or upsert operation
QUOTA_EXCEEDEDStorage/operation quota reachedReview usage or upgrade plan

Auth-Specific Errors

CodeDescriptionResolution
INVALID_CREDENTIALSWrong email/passwordVerify credentials
OTP_EXPIREDOTP code expiredRequest new OTP
OTP_INVALIDIncorrect OTP codeCheck OTP and retry
EMAIL_ALREADY_EXISTSEmail is registeredUse different email or sign in
TOKEN_EXPIREDJWT token expiredRefresh token or re-authenticate
WEAK_PASSWORDPassword doesn't meet policyUse stronger password
EMAIL_NOT_VERIFIEDEmail verification requiredVerify email address

Storage-Specific Errors

CodeDescriptionResolution
FILE_NOT_FOUNDFile doesn't existVerify file key
FILE_TOO_LARGEFile exceeds size limitReduce file size
INVALID_FILE_TYPEUnsupported file formatUse supported file types
UPLOAD_EXPIREDPresigned URL expiredGenerate new presigned URL
PROCESSING_FAILEDImage processing failedCheck image format and retry
STORAGE_QUOTA_EXCEEDEDStorage limit reachedClean up files or upgrade plan

Error Handling Best Practices

Retry Logic

async function apiRequestWithRetry(requestData, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await fetch('https://cloud.singlebaseapis.com/api/$PROJECT-ID', {
method: 'POST',
headers: {
'X-API-KEY': 'your-api-key',
'Authorization': 'Bearer your-token',
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});

if (!response.ok) {
const error = await response.json();

// Don't retry for client errors
if (response.status >= 400 && response.status < 500) {
throw new Error(error.error.message);
}

// Retry for server errors
if (attempt === maxRetries) {
throw new Error(`Max retries reached: ${error.error.message}`);
}

// Exponential backoff
await new Promise(resolve =>
setTimeout(resolve, Math.pow(2, attempt) * 1000)
);
continue;
}

return await response.json();
} catch (error) {
if (attempt === maxRetries) throw error;
}
}
}

Error Response Handling

function handleApiError(error) {
switch (error.error.code) {
case 'AUTHENTICATION_FAILED':
// Redirect to login
redirectToLogin();
break;
case 'TOKEN_EXPIRED':
// Attempt token refresh
refreshAuthToken();
break;
case 'VALIDATION_ERROR':
// Show validation errors to user
showValidationErrors(error.error.details);
break;
case 'RATE_LIMIT_EXCEEDED':
// Implement exponential backoff
scheduleRetry(error.error.details.retry_after);
break;
default:
// Generic error handling
showErrorMessage(error.error.message);
}
}