Ignore 404 errors in GitLab group iteration #4450
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When making requests to the GitLab API, a 404 error can be returned in two scenarios: when attempting to access a resource for which the user lacks permissions, or when querying a resource that does not exist (or has just been deleted).
In the case of missing permissions, GitLab intentionally returns a 404 status code instead of the more conventional 403 to avoid revealing the existence of restricted resources.
To address this issue, this pull request proposes a solution to specifically handle 404 errors occurring on calls made to the /groups/xxx/projects endpoint. If a 404 error is encountered while attempting to list projects within a group, it suggests either a permissions issue or that the group does not contain any projects. In either scenario, it's optimal to manage this situation by proceeding with the iteration through other groups and providing the user with a consolidated list of projects that could be successfully retrieved. Rather than triggering a "404 Group Not Found" error :
The current approach, treating 404 errors as "true" errors and triggering retries via the error callback, leads to unnecessary retries and ultimately does not provide meaningful results.
By treating 404 errors on the /groups/xxx/projects endpoint as expected behavior and handling them accordingly, we can improve the robustness and efficiency of our API requests.