refactor: use Pydantic Field for port, revert async error callback

This commit is contained in:
strawgate 2026-04-14 00:18:30 -05:00
commit 212425a13d
2 changed files with 4 additions and 14 deletions

View file

@ -1,7 +1,6 @@
"""Error handling middleware for consistent error responses and tracking."""
import asyncio
import inspect
import logging
import traceback
from collections.abc import Callable
@ -56,7 +55,7 @@ class ErrorHandlingMiddleware(Middleware):
self.transform_errors = transform_errors
self.error_counts = {}
async def _log_error(self, error: Exception, context: MiddlewareContext) -> None:
def _log_error(self, error: Exception, context: MiddlewareContext) -> None:
"""Log error with appropriate detail level."""
error_type = type(error).__name__
method = context.method or "unknown"
@ -75,9 +74,7 @@ class ErrorHandlingMiddleware(Middleware):
# Call custom error callback if provided
if self.error_callback:
try:
result = self.error_callback(error, context)
if inspect.isawaitable(result):
await result
self.error_callback(error, context)
except Exception as callback_error:
self.logger.error(f"Error in error callback: {callback_error}")
@ -125,7 +122,7 @@ class ErrorHandlingMiddleware(Middleware):
try:
return await call_next(context)
except Exception as error:
await self._log_error(error, context)
self._log_error(error, context)
# Transform and re-raise
transformed_error = self._transform_error(error, context)

View file

@ -185,13 +185,6 @@ class Settings(BaseSettings):
return v.upper()
return v
@field_validator("port")
@classmethod
def _validate_port(cls, v: int) -> int:
if not (1 <= v <= 65535):
raise ValueError(f"Port must be between 1 and 65535, got {v}")
return v
docket: DocketSettings = DocketSettings()
enable_rich_logging: Annotated[
@ -265,7 +258,7 @@ class Settings(BaseSettings):
# HTTP settings
host: str = "127.0.0.1"
port: int = 8000
port: int = Field(default=8000, ge=1, le=65535)
sse_path: str = "/sse"
message_path: str = "/messages/"
streamable_http_path: str = "/mcp"