Merge pull request #1816 from QuantumNous/fix/setup-err-display
🛠️ fix: Align setup API errors to HTTP 200 with {success:false, message}
This commit is contained in:
+10
-10
@@ -53,7 +53,7 @@ func GetSetup(c *gin.Context) {
|
|||||||
func PostSetup(c *gin.Context) {
|
func PostSetup(c *gin.Context) {
|
||||||
// Check if setup is already completed
|
// Check if setup is already completed
|
||||||
if constant.Setup {
|
if constant.Setup {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "系统已经初始化完成",
|
"message": "系统已经初始化完成",
|
||||||
})
|
})
|
||||||
@@ -66,7 +66,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
var req SetupRequest
|
var req SetupRequest
|
||||||
err := c.ShouldBindJSON(&req)
|
err := c.ShouldBindJSON(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "请求参数有误",
|
"message": "请求参数有误",
|
||||||
})
|
})
|
||||||
@@ -77,7 +77,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
if !rootExists {
|
if !rootExists {
|
||||||
// Validate username length: max 12 characters to align with model.User validation
|
// Validate username length: max 12 characters to align with model.User validation
|
||||||
if len(req.Username) > 12 {
|
if len(req.Username) > 12 {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "用户名长度不能超过12个字符",
|
"message": "用户名长度不能超过12个字符",
|
||||||
})
|
})
|
||||||
@@ -85,7 +85,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// Validate password
|
// Validate password
|
||||||
if req.Password != req.ConfirmPassword {
|
if req.Password != req.ConfirmPassword {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "两次输入的密码不一致",
|
"message": "两次输入的密码不一致",
|
||||||
})
|
})
|
||||||
@@ -93,7 +93,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(req.Password) < 8 {
|
if len(req.Password) < 8 {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "密码长度至少为8个字符",
|
"message": "密码长度至少为8个字符",
|
||||||
})
|
})
|
||||||
@@ -103,7 +103,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
// Create root user
|
// Create root user
|
||||||
hashedPassword, err := common.Password2Hash(req.Password)
|
hashedPassword, err := common.Password2Hash(req.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "系统错误: " + err.Error(),
|
"message": "系统错误: " + err.Error(),
|
||||||
})
|
})
|
||||||
@@ -120,7 +120,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err = model.DB.Create(&rootUser).Error
|
err = model.DB.Create(&rootUser).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "创建管理员账号失败: " + err.Error(),
|
"message": "创建管理员账号失败: " + err.Error(),
|
||||||
})
|
})
|
||||||
@@ -135,7 +135,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
// Save operation modes to database for persistence
|
// Save operation modes to database for persistence
|
||||||
err = model.UpdateOption("SelfUseModeEnabled", boolToString(req.SelfUseModeEnabled))
|
err = model.UpdateOption("SelfUseModeEnabled", boolToString(req.SelfUseModeEnabled))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "保存自用模式设置失败: " + err.Error(),
|
"message": "保存自用模式设置失败: " + err.Error(),
|
||||||
})
|
})
|
||||||
@@ -144,7 +144,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
|
|
||||||
err = model.UpdateOption("DemoSiteEnabled", boolToString(req.DemoSiteEnabled))
|
err = model.UpdateOption("DemoSiteEnabled", boolToString(req.DemoSiteEnabled))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "保存演示站点模式设置失败: " + err.Error(),
|
"message": "保存演示站点模式设置失败: " + err.Error(),
|
||||||
})
|
})
|
||||||
@@ -160,7 +160,7 @@ func PostSetup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err = model.DB.Create(&setup).Error
|
err = model.DB.Create(&setup).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "系统初始化失败: " + err.Error(),
|
"message": "系统初始化失败: " + err.Error(),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user