Spaces:
Running
Running
Add detailed error mapping debug logs.
Browse filesWill show exact exception type and mapping path.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 unmodified lines38394041424344454647484950515253545556575859606162636465666768697071727374757637 unmodified linesso reactive 429 handling applies to the correct provider. Tests may omit``rate_limiter`` to use the process-wide singleton."""message = get_user_facing_error_message(e)limiter = rate_limiter or GlobalRateLimiter.get_instance()if isinstance(e, openai.AuthenticationError):return AuthenticationError(message, raw_error=str(e))if isinstance(e, openai.RateLimitError):limiter.set_blocked(60)return RateLimitError(message, raw_error=str(e))if isinstance(e, openai.BadRequestError):return InvalidRequestError(message, raw_error=str(e))if isinstance(e, openai.InternalServerError):raw_message = str(e)if "overloaded" in raw_message.lower() or "capacity" in raw_message.lower():return OverloadedError(message, raw_error=raw_message)return APIError(message, status_code=500, raw_error=str(e))if isinstance(e, openai.APIError):return APIError(message, status_code=getattr(e, "status_code", 500), raw_error=str(e))if isinstance(e, httpx.HTTPStatusError):status = e.response.status_codeif status in (401, 403):return AuthenticationError(message, raw_error=str(e))if status == 429:limiter.set_blocked(60)return RateLimitError(message, raw_error=str(e))if status == 400:return InvalidRequestError(message, raw_error=str(e))if status >= 500:if status in (502, 503, 504):return OverloadedError(message, raw_error=str(e))return APIError(message, status_code=status, raw_error=str(e))return APIError(message, status_code=status, raw_error=str(e))return e37 unmodified lines3839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949537 unmodified linesso reactive 429 handling applies to the correct provider. Tests may omit``rate_limiter`` to use the process-wide singleton."""from loguru import loggermessage = get_user_facing_error_message(e)logger.info("map_error: original_exc_type={} message={}", type(e).__name__, message[:100])limiter = rate_limiter or GlobalRateLimiter.get_instance()if isinstance(e, openai.AuthenticationError):logger.info("map_error: mapped to AuthenticationError")return AuthenticationError(message, raw_error=str(e))if isinstance(e, openai.RateLimitError):limiter.set_blocked(60)logger.info("map_error: mapped to RateLimitError")return RateLimitError(message, raw_error=str(e))if isinstance(e, openai.BadRequestError):logger.info("map_error: mapped to InvalidRequestError")return InvalidRequestError(message, raw_error=str(e))if isinstance(e, openai.InternalServerError):raw_message = str(e)if "overloaded" in raw_message.lower() or "capacity" in raw_message.lower():logger.info("map_error: mapped to OverloadedError")return OverloadedError(message, raw_error=raw_message)logger.info("map_error: mapped to APIError (InternalServerError)")return APIError(message, status_code=500, raw_error=str(e))if isinstance(e, openai.APIError):logger.info("map_error: mapped to APIError (openai.APIError)")return APIError(message, status_code=getattr(e, "status_code", 500), raw_error=str(e))if isinstance(e, httpx.HTTPStatusError):status = e.response.status_codelogger.info("map_error: httpx.HTTPStatusError status={}", status)if status in (401, 403):logger.info("map_error: mapped to AuthenticationError (httpx)")return AuthenticationError(message, raw_error=str(e))if status == 429:limiter.set_blocked(60)logger.info("map_error: mapped to RateLimitError (httpx)")return RateLimitError(message, raw_error=str(e))if status == 400:logger.info("map_error: mapped to InvalidRequestError (httpx)")return InvalidRequestError(message, raw_error=str(e))if status >= 500:if status in (502, 503, 504):logger.info("map_error: mapped to OverloadedError (httpx)")return OverloadedError(message, raw_error=str(e))logger.info("map_error: mapped to APIError (httpx 5xx)")return APIError(message, status_code=status, raw_error=str(e))logger.info("map_error: mapped to APIError (httpx)")return APIError(message, status_code=status, raw_error=str(e))logger.info("map_error: falling through, returning original exception")return e
providers/error_mapping.py+19