mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-02 08:36:51 +08:00
33 lines
566 B
Go
33 lines
566 B
Go
package buserr
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/backend/i18n"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type BusinessError struct {
|
|
Msg string
|
|
Detail interface{}
|
|
Err error
|
|
}
|
|
|
|
func (e BusinessError) Error() string {
|
|
|
|
content := i18n.GetErrMsg(e.Msg, map[string]interface{}{"detail": e.Detail})
|
|
if content == "" {
|
|
if e.Err != nil {
|
|
return e.Err.Error()
|
|
}
|
|
return errors.New(e.Msg).Error()
|
|
}
|
|
return content
|
|
}
|
|
|
|
func New(Key string, detail interface{}, err error) BusinessError {
|
|
return BusinessError{
|
|
Msg: Key,
|
|
Detail: detail,
|
|
Err: err,
|
|
}
|
|
}
|