SENODROOM commited on
Commit
a7f5392
·
1 Parent(s): 68d6af8
app/clients/github_graphql.py CHANGED
@@ -13,9 +13,9 @@ class GitHubAPIError(RuntimeError):
13
  pass
14
 
15
 
16
- def _headers() -> dict[str, str]:
17
  headers = {"Accept": "application/vnd.github+json"}
18
- if settings.github_token:
19
  headers["Authorization"] = f"Bearer {settings.github_token}"
20
  return headers
21
 
@@ -47,6 +47,8 @@ class GitHubGraphQLClient:
47
  response = await client.post(settings.github_api_url, headers=_headers(), json=payload)
48
 
49
  if response.status_code >= 400:
 
 
50
  raise GitHubAPIError(f"GitHub API status={response.status_code}: {response.text}")
51
 
52
  data = response.json()
@@ -58,9 +60,9 @@ class GitHubGraphQLClient:
58
  data["source"] = "graphql"
59
  return data
60
 
61
- async def _analyze_public_user(self, username: str) -> dict[str, Any]:
62
  base_url = settings.github_rest_api_url.rstrip("/")
63
- async with httpx.AsyncClient(base_url=base_url, timeout=settings.request_timeout_seconds, headers=_headers()) as client:
64
  user_response = await client.get(f"/users/{username}")
65
  if user_response.status_code == 404:
66
  raise GitHubAPIError(f"GitHub user '{username}' not found.")
 
13
  pass
14
 
15
 
16
+ def _headers(use_token: bool = True) -> dict[str, str]:
17
  headers = {"Accept": "application/vnd.github+json"}
18
+ if use_token and settings.github_token:
19
  headers["Authorization"] = f"Bearer {settings.github_token}"
20
  return headers
21
 
 
47
  response = await client.post(settings.github_api_url, headers=_headers(), json=payload)
48
 
49
  if response.status_code >= 400:
50
+ if response.status_code == 401:
51
+ return await self._analyze_public_user(username, use_token=False)
52
  raise GitHubAPIError(f"GitHub API status={response.status_code}: {response.text}")
53
 
54
  data = response.json()
 
60
  data["source"] = "graphql"
61
  return data
62
 
63
+ async def _analyze_public_user(self, username: str, use_token: bool = False) -> dict[str, Any]:
64
  base_url = settings.github_rest_api_url.rstrip("/")
65
+ async with httpx.AsyncClient(base_url=base_url, timeout=settings.request_timeout_seconds, headers=_headers(use_token=use_token)) as client:
66
  user_response = await client.get(f"/users/{username}")
67
  if user_response.status_code == 404:
68
  raise GitHubAPIError(f"GitHub user '{username}' not found.")
app/static/index.html CHANGED
@@ -475,7 +475,8 @@ const profileRating = await response.json();`;
475
  renderResult(data);
476
  setStatus(`Finished ${username}.`);
477
  } catch (error) {
478
- setStatus(`${error.message}. Check API Base and confirm FastAPI is running on port 8000.`, true);
 
479
  } finally {
480
  submitButton.disabled = false;
481
  }
 
475
  renderResult(data);
476
  setStatus(`Finished ${username}.`);
477
  } catch (error) {
478
+ const networkHint = error instanceof TypeError ? " Check API Base and confirm FastAPI is running on port 8000." : "";
479
+ setStatus(`${error.message}.${networkHint}`, true);
480
  } finally {
481
  submitButton.disabled = false;
482
  }