WIP: Appropriate Token error #290
Conversation
e4e1c8e to
5ff617f
Compare
…4Energy/SMECS into 240-Appropriate-token-error
Aidajafarbigloo
left a comment
There was a problem hiding this comment.
Thanks for the changes. There are still cases where the system does not display an appropriate error message to the user. Please address this and ensure error handling is consistent across various relevant scenarios, and validate the fix across multiple repositories to cover different cases and conditions.
| headers = {"PRIVATE-TOKEN": token} | ||
| response = requests.get(api_url, headers=headers) | ||
| return response.status_code == 200 | ||
| return {"status": "invalid_url", "message": "Invalid GitLab repository URL format."} |
There was a problem hiding this comment.
returns also for gh repos
| pass | ||
| return { | ||
| "status": "invalid_token", | ||
| "message": "The provided GitLab token is invalid. Please check your token and try again.", |
There was a problem hiding this comment.
Instead I received "Unexpected response from GitLab API (HTTP 400)."
|
What We Changed and Why Change 1 — Smarter URL Detection (classify_url) After: We now parse only the domain part of the URL (e.g. github.company.com) and classify it into one of five types: public GitHub, GitHub Enterprise, public GitLab, self-hosted GitLab, or unknown. This is much more accurate. Change 2 — GitHub Enterprise Support (_build_github_api_url) After: We build the API address from the parsed URL pieces (owner name, repo name, host). For company GitHub servers, the correct API address format (/api/v3/) is used automatically. Change 3 — Unknown Hosts No Longer Treated as GitLab After: Unknown hosts are identified as "unsupported" and shown a clear message. As a bonus, we also probe the host silently to check if it might be a self-hosted GitLab that just doesn't have "gitlab" in its name — if so, we handle it correctly. Change 4 — Consistent Response Format After: All responses now consistently include a forge field (renamed from instance_type) telling the caller exactly what type of platform was detected. Change 5 — Accurate GitHub Token Error Message After: The message now says "invalid or has expired", which is honest about both possibilities and tells the user exactly what to do. |
Aidajafarbigloo
left a comment
There was a problem hiding this comment.
For the scenario where the input URL points to a self-hosted repository, whether the token is valid but does not match the repository, or the token itself is invalid, similar error message as following is appropriate:
"The token is not usable for this type of repository. To extract data from this repository, provide a token that complies with your organization's requirements."
What changed
Before this fix, when something went wrong (wrong token, expired token, wrong URL), the tool would silently fail with a generic or confusing message. Now it tells you exactly what the problem is.
In short: instead of a confusing dead end, you now get a clear message telling you what went wrong and where.
Issue #240 Appropriate error when token is expired (Solved)
Issue #209 Differentiate error between URL and token (Solved)