Add Exception schema
This commit is contained in:
parent
4c61b7fcfe
commit
463636aab9
46
schemas/exception.py
Normal file
46
schemas/exception.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user