From e428b1aa5adb7949c10301a2be5881f5c85d323e Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sat, 29 Mar 2025 22:19:46 +0000 Subject: [PATCH] Add Exception schema --- schemas/exception.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 schemas/exception.py diff --git a/schemas/exception.py b/schemas/exception.py new file mode 100644 index 0000000..9be2beb --- /dev/null +++ b/schemas/exception.py @@ -0,0 +1,44 @@ +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" + } + } \ No newline at end of file