From 1d2b5fad46afced9f7b5457b5996442bb8526971 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Wed, 28 Feb 2024 08:12:01 -0600 Subject: [PATCH] :bug: Return empty list when latest analysis does not exist. (#602) Return empty list of issues when no latest analysis. But still 404 when application not found. https://issues.redhat.com/browse/MTA-2047 Signed-off-by: Jeff Ortel --- api/analysis.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/api/analysis.go b/api/analysis.go index 92efeabb1..0ade90e28 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -919,13 +919,25 @@ func (h AnalysisHandler) AppIssueReports(ctx *gin.Context) { model.Issue Files int } - // Latest id := h.pk(ctx) + err := h.DB(ctx).First(&model.Application{}, id).Error + if err != nil { + _ = ctx.Error(err) + return + } + // Latest analysis := &model.Analysis{} db := h.DB(ctx).Where("ApplicationID", id) - result := db.Last(analysis) - if result.Error != nil { - _ = ctx.Error(result.Error) + err = db.Last(analysis).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + h.Respond( + ctx, + http.StatusOK, + resources) + } else { + _ = ctx.Error(err) + } return } // Filter