use plain error type for expected behaviors (#447)

This commit is contained in:
UUBulb 2024-10-22 10:25:45 +08:00 committed by GitHub
parent 15585ef12e
commit 65aa18300d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View File

@ -105,7 +105,7 @@ func editDDNS(c *gin.Context) error {
var p model.DDNSProfile
if err = singleton.DB.First(&p, id).Error; err != nil {
return newGormError("%v", err)
return fmt.Errorf("profile id %d does not exist", id)
}
p.Name = df.Name

View File

@ -1,6 +1,7 @@
package controller
import (
"fmt"
"net/http"
"strconv"
@ -36,7 +37,7 @@ func editServer(c *gin.Context) error {
var s model.Server
if err := singleton.DB.First(&s, id).Error; err != nil {
return newGormError("%v", err)
return fmt.Errorf("server id %d does not exist", id)
}
s.Name = sf.Name

View File

@ -113,7 +113,7 @@ func newServerGroup(c *gin.Context) error {
// @Param body body model.ServerGroupForm true "ServerGroupForm"
// @Produce json
// @Success 200 {object} model.CommonResponse[any]
// @Router /server-group/{id} [put]
// @Router /server-group/{id} [patch]
func editServerGroup(c *gin.Context) error {
id := c.Param("id")
var sg model.ServerGroupForm
@ -122,7 +122,7 @@ func editServerGroup(c *gin.Context) error {
}
var sgDB model.ServerGroup
if err := singleton.DB.First(&sgDB, id).Error; err != nil {
return newGormError("%v", err)
return fmt.Errorf("group id %s does not exist", id)
}
sgDB.Name = sg.Name