优化提取错误提示消息
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"platform/pkg/env"
|
"platform/pkg/env"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -17,7 +18,8 @@ type Err struct {
|
|||||||
|
|
||||||
func (e *Err) Error() string {
|
func (e *Err) Error() string {
|
||||||
if e.err != nil {
|
if e.err != nil {
|
||||||
return e.msg + ": " + e.err.Error()
|
slog.Debug(fmt.Sprintf("%s: %s", e.msg, e.err.Error()))
|
||||||
|
return e.msg
|
||||||
}
|
}
|
||||||
return e.msg
|
return e.msg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"platform/pkg/u"
|
"platform/pkg/u"
|
||||||
"platform/web/auth"
|
"platform/web/auth"
|
||||||
"platform/web/core"
|
"platform/web/core"
|
||||||
|
g "platform/web/globals"
|
||||||
m "platform/web/models"
|
m "platform/web/models"
|
||||||
q "platform/web/queries"
|
q "platform/web/queries"
|
||||||
s "platform/web/services"
|
s "platform/web/services"
|
||||||
@@ -122,13 +123,13 @@ func CreateChannel(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// 解析参数
|
// 解析参数
|
||||||
req := new(CreateChannelReq)
|
req := new(CreateChannelReq)
|
||||||
if err := c.BodyParser(req); err != nil {
|
if err := g.Validator.Validate(c, req); err != nil {
|
||||||
return err
|
return core.NewBizErr("解析参数失败", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, err := netip.ParseAddr(c.Get(core.HeaderUserIP))
|
ip, err := netip.ParseAddr(c.Get(core.HeaderUserIP))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return core.NewBizErr("解析请求头客户端 IP 地址失败", err)
|
return core.NewBizErr("获取客户端地址失败", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建通道
|
// 创建通道
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ func (s *channelBaiyinService) CreateChannels(source netip.Addr, userId int32, r
|
|||||||
pass := false
|
pass := false
|
||||||
for i, item := range whitelists {
|
for i, item := range whitelists {
|
||||||
whitelistIPs[i] = item.IP.String()
|
whitelistIPs[i] = item.IP.String()
|
||||||
if item.IP.Compare(source) != 0 {
|
if item.IP.Addr == source {
|
||||||
pass = true
|
pass = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !pass {
|
if !pass {
|
||||||
return nil, core.NewBizErr("IP 地址不在白名单内")
|
return nil, core.NewBizErr(fmt.Sprintf("IP 地址 %s 不在白名单内", source.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户套餐并检查
|
// 获取用户套餐并检查
|
||||||
|
|||||||
Reference in New Issue
Block a user