Spaces:
Running
Running
Better handle rate limit errors that come as 413 or BadRequestError.
Browse filesAlso detect rate limits from response body type.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
53 unmodified lines54555657585919 unmodified lines79808182838485868753 unmodified lineslogger.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):19 unmodified lineslimiter.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)")53 unmodified lines54555657585960616263646519 unmodified lines85868788899091929394959697989910010110210310410510610710810953 unmodified lineslogger.info("map_error: mapped to RateLimitError")return RateLimitError(message, raw_error=str(e))if isinstance(e, openai.BadRequestError):# Check if it's actually a rate limit in disguiseraw = str(e).lower()if "too_many_requests" in raw or "rate_limit" in raw or "quota" in raw:limiter.set_blocked(60)logger.info("map_error: BadRequestError actually rate limit")return RateLimitError(message, raw_error=str(e))logger.info("map_error: mapped to InvalidRequestError")return InvalidRequestError(message, raw_error=str(e))if isinstance(e, openai.InternalServerError):19 unmodified lineslimiter.set_blocked(60)logger.info("map_error: mapped to RateLimitError (httpx)")return RateLimitError(message, raw_error=str(e))if status == 413:# "Request too large" - often actually a rate limit or quota issuelimiter.set_blocked(60)logger.info("map_error: mapped to RateLimitError (413)")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))# Check response body for rate limit indicatorstry:body = e.response.json()if body and isinstance(body, dict):err_type = body.get("type", "")if "too_many_requests" in err_type or "rate_limit" in err_type.lower():limiter.set_blocked(60)logger.info("map_error: detected rate limit from response body")return RateLimitError(message, raw_error=str(e))except Exception:passif status >= 500:if status in (502, 503, 504):logger.info("map_error: mapped to OverloadedError (httpx)")
providers/error_mapping.py+22