Enhance API response handling and implement unified API standard across multiple modules. Added feature flags for unified exception handling and debug throttling in settings. Updated pagination and response formats in various viewsets to align with the new standard. Improved error handling and response validation in frontend components for better user feedback.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-15 20:18:42 +00:00
parent 94f243f4a2
commit a75ebf2584
18 changed files with 1974 additions and 642 deletions

View File

@@ -0,0 +1,43 @@
"""
Request ID Middleware
Generates unique request ID for every request and includes it in response headers
"""
import uuid
import logging
from django.utils.deprecation import MiddlewareMixin
logger = logging.getLogger(__name__)
class RequestIDMiddleware(MiddlewareMixin):
"""
Middleware that generates a unique request ID for every request
and includes it in response headers as X-Request-ID
"""
def process_request(self, request):
"""Generate or retrieve request ID"""
# Check if request ID already exists in headers
request_id = request.META.get('HTTP_X_REQUEST_ID') or request.META.get('X-Request-ID')
if not request_id:
# Generate new request ID
request_id = str(uuid.uuid4())
# Store in request for use in views/exception handlers
request.request_id = request_id
return None
def process_response(self, request, response):
"""Add request ID to response headers"""
# Get request ID from request
request_id = getattr(request, 'request_id', None)
if request_id:
# Add to response headers
response['X-Request-ID'] = request_id
return response