mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:09:24 +08:00
67 lines
1.5 KiB
Python
67 lines
1.5 KiB
Python
"""
|
|
Base exception classes for consistent error handling across the application.
|
|
Provides a standardized way to distinguish between bugs, recoverable errors,
|
|
and configuration issues.
|
|
"""
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
class DeepTutorError(Exception):
|
|
"""Base class for all application errors in DeepTutor."""
|
|
|
|
def __init__(self, message: str, details: Optional[Dict[str, Any]] = None):
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.details = details or {}
|
|
|
|
def __str__(self) -> str:
|
|
if self.details:
|
|
return f"{self.message} (details: {self.details})"
|
|
return self.message
|
|
|
|
|
|
class ConfigurationError(DeepTutorError):
|
|
"""Raised when there's a configuration-related error."""
|
|
|
|
pass
|
|
|
|
|
|
class ValidationError(DeepTutorError):
|
|
"""Raised when input validation fails."""
|
|
|
|
pass
|
|
|
|
|
|
class ServiceError(DeepTutorError):
|
|
"""Base class for service layer errors."""
|
|
|
|
pass
|
|
|
|
|
|
class LLMServiceError(ServiceError):
|
|
"""Base class for LLM service-related errors."""
|
|
|
|
pass
|
|
|
|
|
|
class LLMContextError(LLMServiceError):
|
|
"""Raised when prompt exceeds model context window."""
|
|
|
|
pass
|
|
|
|
|
|
class EnvironmentConfigError(ConfigurationError):
|
|
"""Raised when there's an environment-related configuration error."""
|
|
|
|
pass
|
|
|
|
|
|
class AccessError(DeepTutorError):
|
|
"""Transport-independent access failure, translated by HTTP adapters."""
|
|
|
|
def __init__(self, status_code: int, detail: str):
|
|
super().__init__(detail)
|
|
self.status_code = status_code
|
|
self.detail = detail
|