diff --git a/internal/router/ui.go b/internal/router/ui.go index 99bcaf07..852f6b06 100644 --- a/internal/router/ui.go +++ b/internal/router/ui.go @@ -4,6 +4,7 @@ import ( "embed" "fmt" "io/fs" + "math/rand" "net/http" "os" @@ -11,6 +12,7 @@ import ( "github.com/answerdev/answer/internal/base/handler" "github.com/answerdev/answer/ui" "github.com/gin-gonic/gin" + "github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/log" ) @@ -93,11 +95,29 @@ func (a *UIRouter) Register(r *gin.Engine) { }) r.POST("/installation/db/check", func(c *gin.Context) { - handler.HandleResponse(c, nil, gin.H{}) + num := rand.Intn(10) + if num > 5 { + err := errors.BadRequest("connection error") + handler.HandleResponse(c, err, gin.H{}) + } else { + handler.HandleResponse(c, nil, gin.H{ + "connection_success": true, + }) + } }) r.POST("/installation/config-file/check", func(c *gin.Context) { - handler.HandleResponse(c, nil, gin.H{}) + num := rand.Intn(10) + if num > 5 { + handler.HandleResponse(c, nil, gin.H{ + "exist": true, + }) + } else { + handler.HandleResponse(c, nil, gin.H{ + "exist": false, + }) + } + }) r.POST("/installation/init", func(c *gin.Context) {