fix: re-raise HTTPException in RequestLoggingMiddleware
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Has been cancelled
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Has been cancelled
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Has been cancelled
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Has been cancelled
Cross-Chain Functionality Tests / aggregate-results (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Has been cancelled
Multi-Node Blockchain Health Monitoring / health-check (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
P2P Network Verification / p2p-verification (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

The middleware was catching all exceptions including HTTPException
and returning a generic 503 'Internal server error', masking the real
error details. Added 'except HTTPException: raise' before the generic
except block so HTTPExceptions propagate correctly with their original
status code and detail message.

Also removed debug logging from leave_island handler.
This commit is contained in:
aitbc
2026-05-15 06:05:01 +02:00
parent a8440e12d1
commit ef8c1f216e
2 changed files with 3 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ import os
import time
from collections import defaultdict
from contextlib import asynccontextmanager
from fastapi import APIRouter, FastAPI, Request
from fastapi import APIRouter, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, PlainTextResponse
from starlette.middleware.base import BaseHTTPMiddleware
@@ -85,6 +85,8 @@ class RequestLoggingMiddleware(BaseHTTPMiddleware):
elif response.status_code >= 400:
metrics_registry.increment("rpc_client_errors_total")
return response
except HTTPException:
raise
except Exception as exc:
duration = time.perf_counter() - start
metrics_registry.increment("rpc_unhandled_errors_total")

View File

@@ -1849,21 +1849,16 @@ async def join_island(request: JoinIslandRequest) -> JoinIslandResponse:
@router.post("/islands/leave", summary="Leave an island")
@rate_limit(rate=100, per=60)
async def leave_island(request: LeaveIslandRequest) -> LeaveIslandResponse:
"""
Leave an island.
Calls IslandManager.leave_island to remove the node from the specified island.
"""
island_manager = get_island_manager()
logger.info(f'leave_island: island_manager={island_manager}')
if island_manager is None:
logger.error('leave_island: island_manager is None!')
raise HTTPException(status_code=503, detail="Island manager not available")
logger.info(f'leave_island: calling leave_island for {request.island_id}')
success = island_manager.leave_island(request.island_id)
logger.info(f'leave_island: result={success}')
if success:
return LeaveIslandResponse(