Spaces:
Running
Running
File size: 1,519 Bytes
676582c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
"""
Error response schemas for structured error handling.
"""
from typing import Optional, Literal
from pydantic import BaseModel
class ErrorResponse(BaseModel):
"""Structured error response model."""
error_code: str
detail: str
source: Literal["AI_PROVIDER", "AUTHENTICATION", "VALIDATION", "DATABASE", "INTERNAL"]
provider: Optional[str] = None
class Config:
json_schema_extra = {
"example": {
"error_code": "RATE_LIMIT_EXCEEDED",
"detail": "AI service rate limit exceeded. Please wait a moment and try again.",
"source": "AI_PROVIDER",
"provider": "gemini"
}
}
# Error code constants
class ErrorCode:
"""Standard error codes for the application."""
# AI Provider errors
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED"
API_KEY_MISSING = "API_KEY_MISSING"
API_KEY_INVALID = "API_KEY_INVALID"
PROVIDER_UNAVAILABLE = "PROVIDER_UNAVAILABLE"
PROVIDER_ERROR = "PROVIDER_ERROR"
# Authentication errors
UNAUTHORIZED = "UNAUTHORIZED"
TOKEN_EXPIRED = "TOKEN_EXPIRED"
TOKEN_INVALID = "TOKEN_INVALID"
# Validation errors
INVALID_INPUT = "INVALID_INPUT"
MESSAGE_TOO_LONG = "MESSAGE_TOO_LONG"
MESSAGE_EMPTY = "MESSAGE_EMPTY"
# Database errors
CONVERSATION_NOT_FOUND = "CONVERSATION_NOT_FOUND"
DATABASE_ERROR = "DATABASE_ERROR"
# Internal errors
INTERNAL_ERROR = "INTERNAL_ERROR"
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|