from pydantic import BaseModel, Field from typing import Optional from datetime import datetime from uuid import UUID class ExceptionBase(BaseModel): error_code: str = Field(..., max_length=50) error_message: str = Field(..., max_length=255) stack_trace: Optional[str] = Field(None) endpoint: str = Field(..., max_length=100) method: str = Field(..., max_length=10) request_data: Optional[str] = Field(None) class ExceptionCreate(ExceptionBase): class Config: schema_extra = { "example": { "error_code": "ERR_500", "error_message": "Internal Server Error", "stack_trace": "File 'app.py', line 50, in process_request\n raise Exception('Database connection failed')", "endpoint": "/api/v1/users", "method": "POST", "request_data": '{"username": "john_doe", "email": "john@example.com"}' } } class Exception(ExceptionBase): id: UUID created_at: datetime class Config: orm_mode = True schema_extra = { "example": { "id": "550e8400-e29b-41d4-a716-446655440000", "error_code": "ERR_500", "error_message": "Internal Server Error", "stack_trace": "File 'app.py', line 50, in process_request\n raise Exception('Database connection failed')", "endpoint": "/api/v1/users", "method": "POST", "request_data": '{"username": "john_doe", "email": "john@example.com"}', "created_at": "2023-01-01T12:00:00" } }