Handle case where there is no latest pipeline for GetBadge (#2042)

address  error 2 of #2036
This commit is contained in:
6543 2023-07-28 00:34:22 +02:00 committed by GitHub
parent bc2e2c7a1b
commit 6d373daea0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -80,7 +80,9 @@ func GetBadge(c *gin.Context) {
pipeline, err := _store.GetPipelineLast(repo, branch)
if err != nil {
log.Warn().Err(err).Msg("")
if !errors.Is(err, types.RecordNotExist) {
log.Warn().Err(err).Msg("could not get last pipeline for badge")
}
pipeline = nil
}
@ -110,7 +112,12 @@ func GetCC(c *gin.Context) {
}
pipelines, err := _store.GetPipelineList(repo, &model.ListOptions{Page: 1, PerPage: 1})
if err != nil || len(pipelines) == 0 {
if err != nil && !errors.Is(err, types.RecordNotExist) {
log.Warn().Err(err).Msg("could not get pipeline list")
c.AbortWithStatus(http.StatusInternalServerError)
return
}
if len(pipelines) == 0 {
c.AbortWithStatus(http.StatusNotFound)
return
}