Add Exception schema
This commit is contained in:
parent
17fe835107
commit
3fa765356a
41
schemas/exception.py
Normal file
41
schemas/exception.py
Normal file
@ -0,0 +1,41 @@
|
||||
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, description="Error code identifier")
|
||||
message: str = Field(..., max_length=255, description="Error message")
|
||||
details: Optional[str] = Field(None, description="Additional error details")
|
||||
stack_trace: Optional[str] = Field(None, description="Stack trace of the error")
|
||||
source: str = Field(..., max_length=100, description="Source of the error")
|
||||
|
||||
class ExceptionCreate(ExceptionBase):
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"error_code": "ERR_001",
|
||||
"message": "Invalid input parameters",
|
||||
"details": "Username must be at least 3 characters long",
|
||||
"stack_trace": "File 'app.py', line 25, in process_user\n raise ValidationError(...)",
|
||||
"source": "UserService"
|
||||
}
|
||||
}
|
||||
|
||||
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_001",
|
||||
"message": "Invalid input parameters",
|
||||
"details": "Username must be at least 3 characters long",
|
||||
"stack_trace": "File 'app.py', line 25, in process_user\n raise ValidationError(...)",
|
||||
"source": "UserService",
|
||||
"created_at": "2023-01-01T00:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user