unsloth/studio/backend/hub/utils/hf_errors.py
Eyera aec41d17ed
feat(studio): Hub + Download Manager (#5916)
Adds the Studio Hub and download manager: browse Hugging Face models and datasets, download GGUF and safetensors with live progress and cancellation, and manage on-device inventory. The Hub does not require a GPU, so it is available on chat-only hosts.

CI: all substantive checks pass, including the three Core jobs after unsloth-zoo#736. The two red checks are non-code flakes, a transient npm-registry DNS resolution failure in the package scan and one quantized vision-model output assertion whose sibling shards passed.
2026-06-09 04:11:24 -07:00

28 lines
908 B
Python

# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
"""Map Hugging Face Hub client-side errors to HTTP status codes."""
from __future__ import annotations
from typing import Optional
def hf_error_status(exc: Exception) -> Optional[int]:
# Client-side HF errors should surface as 4xx, not a generic 500.
name = type(exc).__name__
if name in (
"RepositoryNotFoundError",
"RevisionNotFoundError",
"EntryNotFoundError",
):
return 404
if name == "GatedRepoError":
return 403
if name == "HFValidationError":
return 400
# HfHubHTTPError subclasses carry the upstream response status.
code = getattr(getattr(exc, "response", None), "status_code", None)
if isinstance(code, int) and 400 <= code < 500:
return code
return None