2025-03-28 17:13:00 +00:00

46 lines
1.8 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from uuid import UUID
class ExceptionBase(BaseModel):
endpoint: str = Field(..., description="API endpoint where exception occurred")
method: str = Field(..., description="HTTP method of the request")
status_code: str = Field(..., description="HTTP status code of the error")
error_message: Optional[str] = Field(None, description="Error message details")
stack_trace: Optional[str] = Field(None, description="Stack trace of the error")
request_data: Optional[str] = Field(None, description="Request data when error occurred")
class ExceptionCreate(ExceptionBase):
class Config:
schema_extra = {
"example": {
"endpoint": "/api/users",
"method": "POST",
"status_code": "500",
"error_message": "Internal Server Error",
"stack_trace": "Traceback (most recent call last)...",
"request_data": '{"username": "john", "email": "john@example.com"}'
}
}
class Exception(ExceptionBase):
id: UUID
created_at: datetime
updated_at: datetime
class Config:
orm_mode = True
schema_extra = {
"example": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"endpoint": "/api/users",
"method": "POST",
"status_code": "500",
"error_message": "Internal Server Error",
"stack_trace": "Traceback (most recent call last)...",
"request_data": '{"username": "john", "email": "john@example.com"}',
"created_at": "2023-01-01T00:00:00",
"updated_at": "2023-01-01T00:00:00"
}
}