return 404 code when delete not exist experiment (#96)

Signed-off-by: Pablo Caderno <kaderno@gmail.com>
This commit is contained in:
Pablo Caderno 2021-10-08 16:55:08 +11:00 committed by GitHub
parent d795cf65e5
commit 684f94e20d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/joomcode/errorx"
"github.com/pingcap/log"
"go.uber.org/zap"
"gorm.io/gorm"
"github.com/chaos-mesh/chaosd/pkg/config"
"github.com/chaos-mesh/chaosd/pkg/core"
@ -272,6 +273,10 @@ func (s *httpServer) recoverAttack(c *gin.Context) {
}
func handleError(c *gin.Context, err error) {
if err == gorm.ErrRecordNotFound {
_ = c.AbortWithError(http.StatusNotFound, utils.ErrNotFound.WrapWithNoMessage(err))
return
}
if errorx.IsOfType(err, core.ErrAttackConfigValidation) {
_ = c.AbortWithError(http.StatusBadRequest, utils.ErrInvalidRequest.WrapWithNoMessage(err))
} else {