Skip to content

Commit

Permalink
fix: response 500 if code project is not found
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <[email protected]>
  • Loading branch information
xuzhu-591 committed Feb 27, 2024
1 parent f8bd460 commit b5d0925
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/http/api/v1/code/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/horizoncd/horizon/core/common"
"github.com/horizoncd/horizon/core/controller/code"
herrors "github.com/horizoncd/horizon/core/errors"
perror "github.com/horizoncd/horizon/pkg/errors"
"github.com/horizoncd/horizon/pkg/git"
"github.com/horizoncd/horizon/pkg/server/request"
"github.com/horizoncd/horizon/pkg/server/response"
"github.com/horizoncd/horizon/pkg/server/rpcerror"
"github.com/horizoncd/horizon/pkg/util/log"
)

Expand Down Expand Up @@ -56,6 +59,10 @@ func (a *API) ListBranch(c *gin.Context) {
})
if err != nil {
log.Errorf(c, "List branch error: %+v", err)
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
}
response.AbortWithError(c, err)
return
}
Expand All @@ -81,6 +88,10 @@ func (a *API) ListTag(c *gin.Context) {
PageSize: pageSize,
})
if err != nil {
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
}
response.AbortWithError(c, err)
return
}
Expand Down
11 changes: 11 additions & 0 deletions core/http/api/v2/code/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/horizoncd/horizon/core/common"
"github.com/horizoncd/horizon/core/controller/code"
herrors "github.com/horizoncd/horizon/core/errors"
perror "github.com/horizoncd/horizon/pkg/errors"
"github.com/horizoncd/horizon/pkg/git"
"github.com/horizoncd/horizon/pkg/server/request"
"github.com/horizoncd/horizon/pkg/server/response"
"github.com/horizoncd/horizon/pkg/server/rpcerror"
"github.com/horizoncd/horizon/pkg/util/log"
)

Expand Down Expand Up @@ -56,6 +59,10 @@ func (a *API) ListBranch(c *gin.Context) {
})
if err != nil {
log.Errorf(c, "List branch error: %+v", err)
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
}
response.AbortWithError(c, err)
return
}
Expand All @@ -81,6 +88,10 @@ func (a *API) ListTag(c *gin.Context) {
PageSize: pageSize,
})
if err != nil {
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
}
response.AbortWithError(c, err)
return
}
Expand Down

0 comments on commit b5d0925

Please sign in to comment.