Skip to content

Error Reference

Complete reference of error codes and responses returned by the Singlebase API.

Response Format

All errors return this structure:

json
{
  "type": "NOT_FOUND",
  "status": 404,
  "message": "USER_NOT_FOUND",
  "details": {},
  "trace_id": "abc-123"
}
FieldTypeDescription
typestringError category (matches HTTP status)
statusintegerHTTP status code
messagestringError code or description
detailsobjectAdditional context (optional)
trace_idstringError tracking ID (optional)

Error Codes

400 - Bad Request

Invalid request format or parameters. This occurs when the request is malformed, contains invalid data, or is missing required fields.

CodeDescription
BAD_REQUESTGeneric bad request
VALIDATION_ERRORValidation failed
MISSING_REQUIRED_FIELDRequired field missing
INVALID_LENGTHString/array length invalid
INVALID_JSONMalformed JSON
INVALID_HEADERInvalid HTTP header
INVALID_FILE_FORMATUnsupported file format
BATCH_LIMIT_EXCEEDEDToo many items in batch

401 - Unauthorized

Authentication is required or has failed. This occurs when credentials are missing, invalid, or expired.

CodeDescription
AUTHENTICATION_ERRORAuthentication failed
INVALID_CREDENTIALSWrong username/password
INVALID_TOKENMalformed token

403 - Forbidden

Access to the resource is denied. This occurs when authenticated but lacking proper permissions or the resource is restricted.

CodeDescription
FORBIDDEN_ERRORAccess forbidden
FORBIDDEN_RESOURCEResource access denied
RESOURCE_LOCKEDResource locked

404 - Not Found

The requested resource does not exist. This occurs when the resource has been deleted, archived, or never existed.

CodeDescription
NOT_FOUNDResource not found
DELETEDResource deleted
ARCHIVEDResource archived
EMPTYCollection empty
ACTION_NOT_FOUNDAction not found

405 - Method Not Allowed

HTTP method not supported for this endpoint. This occurs when using the wrong HTTP verb (GET, POST, etc.) for a specific operation.

CodeDescription
METHOD_NOT_ALLOWEDHTTP method not supported

406 - Not Acceptable

Requested media type cannot be provided. This occurs when the server cannot produce a response matching the Accept header.

CodeDescription
UNSUPPORTED_MEDIA_TYPEMedia type not supported

408 - Request Timeout

Request took too long to complete. This occurs when the server terminates a connection that's taking too long to process.

CodeDescription
REQUEST_TIMEOUTRequest took too long

409 - Conflict

Request conflicts with current resource state. This occurs when trying to create a duplicate resource or violating data constraints.

CodeDescription
CONFLICTResource conflict

413 - Payload Too Large

Request body exceeds size limit. This occurs when uploading files or sending data that's too large.

CodeDescription
REQUEST_ENTITY_TOO_LARGERequest body too large

415 - Unsupported Media Type

Content-Type header not supported. This occurs when sending data in an unsupported format.

CodeDescription
UNSUPPORTED_CONTENT_TYPEContent-Type not supported

429 - Too Many Requests

Rate limit exceeded. This occurs when making too many requests in a given time period or exceeding usage quotas.

CodeDescription
TOO_MANY_REQUESTSRate limit exceeded
RATE_LIMIT_EXCEEDEDRequest rate too high
QUOTA_EXCEEDEDUsage quota exceeded

500 - Internal Server Error

Server encountered an unexpected error. This occurs when something goes wrong on the server side.

CodeDescription
SERVER_ERRORGeneric server error

503 - Service Unavailable

Service is temporarily unavailable. This occurs during maintenance or when the service is overloaded.

CodeDescription
SERVICE_UNAVAILABLEService temporarily unavailable
MAINTENANCE_MODEUnder maintenance

Examples

Validation Error

json
{
  "type": "VALIDATION_ERROR",
  "status": 400,
  "message": "MISSING_REQUIRED_FIELD",
  "details": {
    "field": "email",
    "requirement": "required"
  }
}

Authentication Error

json
{
  "type": "EXPIRED_TOKEN",
  "status": 401,
  "message": "TOKEN_EXPIRED",
  "details": {
    "expired_at": "2024-01-15T10:30:00Z"
  }
}

Not Found

json
{
  "type": "NOT_FOUND",
  "status": 404,
  "message": "USER_NOT_FOUND",
  "details": {
    "user_id": "12345"
  }
}

Rate Limit

json
{
  "type": "RATE_LIMIT_EXCEEDED",
  "status": 429,
  "message": "TOO_MANY_REQUESTS",
  "details": {
    "limit": 100,
    "window": "1h",
    "retry_after": 3600
  }
}

Error Handling Best Practices

Retry Logic

javascript
async function apiRequestWithRetry(requestData, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const response = await fetch('https://cloud.singlebaseapis.com/api/$ENDPOINT_KEY', {
        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.message);
        }
        
        // Retry for server errors
        if (attempt === maxRetries) {
          throw new Error(`Max retries reached: ${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

javascript
function handleApiError(error) {
  switch (error.type) {
    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.details);
      break;
    case 'RATE_LIMIT_EXCEEDED':
      // Implement exponential backoff
      scheduleRetry(error.details.retry_after);
      break;
    default:
      // Generic error handling
      showErrorMessage(error.message);
  }
}