优化表结构,重构模型,重新实现基于白银网关的提取节点流程
This commit is contained in:
68
web/core/error.go
Normal file
68
web/core/error.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"platform/pkg/env"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type Err struct {
|
||||
msg string
|
||||
err error
|
||||
|
||||
errFile string
|
||||
errLine int
|
||||
errFunc string
|
||||
}
|
||||
|
||||
func (e *Err) Error() string {
|
||||
if e.err != nil {
|
||||
return e.msg + ": " + e.err.Error()
|
||||
}
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func (e *Err) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e *Err) Source() *slog.Source {
|
||||
return &slog.Source{
|
||||
Function: e.errFunc,
|
||||
File: e.errFile,
|
||||
Line: e.errLine,
|
||||
}
|
||||
}
|
||||
|
||||
func newErr(msg string, err ...error) Err {
|
||||
o := Err{
|
||||
msg: msg,
|
||||
}
|
||||
|
||||
if len(err) > 0 {
|
||||
o.err = err[0]
|
||||
}
|
||||
|
||||
if env.RunMode == env.RunModeDev {
|
||||
pc, file, line, ok := runtime.Caller(2)
|
||||
if ok {
|
||||
o.errFile = file
|
||||
o.errLine = line
|
||||
o.errFunc = runtime.FuncForPC(pc).Name()
|
||||
}
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
type BizErr struct{ Err }
|
||||
|
||||
func NewBizErr(msg string, err ...error) (biz *BizErr) {
|
||||
return &BizErr{newErr(msg, err...)}
|
||||
}
|
||||
|
||||
type ServErr struct{ Err }
|
||||
|
||||
func NewServErr(msg string, err ...error) *ServErr {
|
||||
return &ServErr{newErr(msg, err...)}
|
||||
}
|
||||
Reference in New Issue
Block a user