Error Handling
Error Response Format
All API errors follow a consistent JSON structure:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Field validation failed",
"details": [
{
"field": "email",
"rule": "unique",
"message": "A document with this email already exists"
}
],
"request_id": "req_abc123"
}
}HTTP Status Codes
| Code | Meaning | When |
|---|---|---|
200 | OK | Successful GET/PUT |
201 | Created | Successful POST |
400 | Bad Request | Invalid parameters |
401 | Unauthorized | Missing or invalid auth |
403 | Forbidden | Insufficient permissions |
404 | Not Found | Resource does not exist |
409 | Conflict | Duplicate unique field |
429 | Too Many Requests | Rate limit exceeded |
500 | Server Error | Internal error |
Error Codes
Authentication Errors
AUTH_REQUIRED— No authentication token providedAUTH_INVALID— Token is malformed or expiredAUTH_INSUFFICIENT— Token lacks required scope
Validation Errors
VALIDATION_ERROR— Field validation failedSCHEMA_MISMATCH— Document does not match collection schemaREQUIRED_FIELD— Required field is missing
Handling Errors in Code
try {
await db.collection("users").insert({ name: "Jane" });
} catch (error) {
if (error.code === "VALIDATION_ERROR") {
console.error("Validation failed:", error.details);
} else if (error.code === "AUTH_REQUIRED") {
// Redirect to login
} else {
console.error("Unexpected error:", error.message);
}
}Rate Limiting
API responses include rate limit headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1710532800