handling exception in list repo refs more gracefully
Browse files
app.py
CHANGED
@@ -35,7 +35,11 @@ def repo_files(r_type: str, r_id: str) -> dict:
|
|
35 |
|
36 |
|
37 |
def repo_size(r_type, r_id):
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
repo_sizes = {}
|
40 |
for branch in r_refs.branches:
|
41 |
try:
|
@@ -44,10 +48,11 @@ def repo_size(r_type, r_id):
|
|
44 |
timeout=1000,
|
45 |
)
|
46 |
response = response.json()
|
47 |
-
# get the status code
|
48 |
except Exception:
|
49 |
response = {}
|
50 |
-
if response.get("error") and
|
|
|
|
|
51 |
gr.Warning(f"Branch information for {r_id} not available.")
|
52 |
return {}
|
53 |
size = response.get("size")
|
|
|
35 |
|
36 |
|
37 |
def repo_size(r_type, r_id):
|
38 |
+
try:
|
39 |
+
r_refs = HF_API.list_repo_refs(repo_id=r_id, repo_type=r_type)
|
40 |
+
except RepositoryNotFoundError:
|
41 |
+
gr.Warning(f"Repository is gated, branch information for {r_id} not available.")
|
42 |
+
return {}
|
43 |
repo_sizes = {}
|
44 |
for branch in r_refs.branches:
|
45 |
try:
|
|
|
48 |
timeout=1000,
|
49 |
)
|
50 |
response = response.json()
|
|
|
51 |
except Exception:
|
52 |
response = {}
|
53 |
+
if response.get("error") and (
|
54 |
+
"restricted" in response.get("error") or "gated" in response.get("error")
|
55 |
+
):
|
56 |
gr.Warning(f"Branch information for {r_id} not available.")
|
57 |
return {}
|
58 |
size = response.get("size")
|