PLEXICHATNarrative Docs

Errors

Guides, route-group overviews, and live schema entry points for the Plexichat backend.

REST http://api.plexichat.com/api/v1Gateway ws://api.plexichat.com/gatewayVersion a.1.0-49

Error Handling

All API errors follow a consistent format.

Error Response Format


{
  "error": {
    "code": 404,
    "message": "Resource not found"
  }
}
FieldTypeDescription
codeint/stringError code (HTTP status or custom)
messagestringHuman-readable error message

HTTP Status Codes

CodeDescription
200Success
201Created
400Bad Request - Invalid input
401Unauthorized - Authentication required
403Forbidden - Permission denied
404Not Found - Resource doesn't exist
409Conflict - Resource already exists
426Upgrade Required - Client update needed
429Too Many Requests - Rate limited
500Internal Server Error
503Service Unavailable - Module not available

Common Error Messages

Authentication Errors (401)

MessageDescription
Authentication requiredNo token provided
Invalid tokenToken is malformed or invalid
Token expiredToken has expired
Invalid credentialsWrong username/password
Invalid codeWrong 2FA code
Expired tokenChallenge token expired

Permission Errors (403)

MessageDescription
Access deniedNo access to resource
Permission deniedMissing required permission
Account lockedToo many failed login attempts
Admin access requiredAdmin permission needed
Cannot message this userUser has blocked you

Validation Errors (400)

MessageDescription
Invalid inputRequest validation failed
Invalid user IDID format invalid
Invalid channel IDID format invalid
Invalid server IDID format invalid
Invalid message IDID format invalid
Weak passwordPassword doesn't meet requirements
Message must have content...Empty message
File too largeUpload exceeds size limit
Invalid file typeUnsupported file format

Resource Errors (404)

MessageDescription
User not foundUser doesn't exist
Server not foundServer doesn't exist
Channel not foundChannel doesn't exist
Message not foundMessage doesn't exist
Webhook not foundWebhook doesn't exist
Session not foundSession doesn't exist
Friend request not foundNo pending request
Relationship not foundNo relationship exists
Setting not foundSetting key doesn't exist

Conflict Errors (409)

MessageDescription
Already existsResource already exists
Username already takenUsername is in use
Email already takenEmail is in use
Already a memberAlready in server
2FA is already enabled2FA already active

Version Errors

Version-related errors include additional fields:


{
  "error": {
    "code": "VERSION_OUTDATED",
    "message": "Client version a.0.9-1 is no longer supported",
    "client_version": "a.0.9-1",
    "min_version": "a.1.0-1",
    "server_version": "a.1.0-1",
    "update_url": "https://..."
  }
}
CodeHTTP StatusDescription
VERSION_OUTDATED426Client must update
INVALID_VERSION_FORMAT400Malformed version string

Rate Limit Errors (429)


{
  "error": {
    "code": 429,
    "message": "Rate limited",
    "retry_after": 1.5
  }
}
FieldDescription
retry_afterSeconds to wait before retrying

Error Handling Best Practices

  1. Check HTTP status code first
  2. Parse error body for details
  3. Handle specific codes appropriately
  4. Use exponential backoff for retries
  5. Display user-friendly messages

Example Error Handling


import time

def api_request(url, **kwargs):
    response = requests.request(url, **kwargs)
    
    if response.status_code == 200:
        return response.json()
    
    elif response.status_code == 401:
        # Re-authenticate
        refresh_token()
        return retry_request()
    
    elif response.status_code == 429:
        # Rate limited - wait and retry
        error = response.json().get("error", {})
        retry_after = error.get("retry_after", 1)
        time.sleep(retry_after)
        return retry_request()
    
    elif response.status_code == 426:
        # Update required
        show_update_prompt()
        return None
    
    else:
        error = response.json().get("error", {})
        log_error(error.get("code"), error.get("message"))
        raise APIError(error.get("message"))

async function apiRequest(url, options) {
    const response = await fetch(url, options);
    
    if (response.ok) {
        return response.json();
    }
    
    const error = await response.json();
    
    if (response.status === 429) {
        const retryAfter = error.error?.retry_after || 1;
        await sleep(retryAfter * 1000);
        return apiRequest(url, options);
    }
    
    throw new Error(error.error?.message || 'Unknown error');
}