ppanel-server/pkg/xerr/errors.go
2025-09-27 10:17:16 +08:00

43 lines
881 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package xerr
import (
"errors"
"fmt"
)
/**
General common fixed error
*/
type CodeError struct {
errCode uint32
errMsg string
}
var StatusNotModified = errors.New("304 Not Modified")
// GetErrCode returns the error code displayed to the front end
func (e *CodeError) GetErrCode() uint32 {
return e.errCode
}
// GetErrMsg returns the error message displayed to the front end
func (e *CodeError) GetErrMsg() string {
return e.errMsg
}
func (e *CodeError) Error() string {
return fmt.Sprintf("ErrCode:%dErrMsg:%s", e.errCode, e.errMsg)
}
func NewErrCodeMsg(errCode uint32, errMsg string) *CodeError {
return &CodeError{errCode: errCode, errMsg: errMsg}
}
func NewErrCode(errCode uint32) *CodeError {
return &CodeError{errCode: errCode, errMsg: MapErrMsg(errCode)}
}
func NewErrMsg(errMsg string) *CodeError {
return &CodeError{errCode: ERROR, errMsg: errMsg}
}