ecommerce-7runez/schemas/exception.py
2025-03-29 22:41:02 +00:00

41 lines
1.6 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from uuid import UUID
class ExceptionBase(BaseModel):
error_code: str = Field(..., description="Error code identifier")
error_message: str = Field(..., description="Detailed error message")
stack_trace: Optional[str] = Field(None, description="Stack trace of the error")
endpoint: str = Field(..., description="API endpoint where error occurred")
request_data: Optional[str] = Field(None, description="Request data when error occurred")
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",
"request_data": "{'user_id': '123', 'action': 'update'}"
}
}
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",
"request_data": "{'user_id': '123', 'action': 'update'}",
"created_at": "2023-01-01T00:00:00"
}
}