Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func (api *limesAPI) getCommitments(ctx context.Context, project identity.Projec
return nil, err
}
defer resp.Body.Close()

// This can happen if a project was deleted after we fetched the list of projects but before we fetched the commitments for the project.
// In this case, we can simply ignore the error and return an empty list of commitments for the project.
if resp.StatusCode == http.StatusNotFound {
slog.Warn("limes returned 404 for project, skipping", "projectID", project.ID, "domainID", project.DomainID)
return []Commitment{}, nil
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ func TestLimesAPI_GetAllCommitments_MultipleProjects(t *testing.T) {
}
})

handler.HandleFunc("/v1/domains/domain1/projects/project-deleted/commitments", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
_, err := w.Write([]byte(`{"error": "project not found"}`))
if err != nil {
t.Fatalf("failed to write response: %v", err)
}
})

server := httptest.NewServer(handler)
defer server.Close()

Expand All @@ -162,6 +171,8 @@ func TestLimesAPI_GetAllCommitments_MultipleProjects(t *testing.T) {
projects := []identity.Project{
{ID: "project1", DomainID: "domain1"},
{ID: "project2", DomainID: "domain1"},
// Returns a 404, should be handled gracefully and not cause the entire API call to fail.
{ID: "project-deleted", DomainID: "domain1"},
}
commitments, err := api.GetAllCommitments(ctx, projects)
if err != nil {
Expand Down