Skip to content

Commit

Permalink
Handle case where there is no latest pipeline for GetBadge (woodpecke…
Browse files Browse the repository at this point in the history
…r-ci#2042)

address  error 2 of woodpecker-ci#2036
  • Loading branch information
6543 authored and mzampetakis committed Jul 31, 2023
1 parent fdcda8b commit f357339
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions server/api/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f357339

Please sign in to comment.