go18/book/v3/exception/common.go
2025-05-11 17:19:48 +08:00

36 lines
671 B
Go

package exception
import (
"fmt"
)
const (
CODE_SERVER_ERROR = 5000
CODE_NOT_FOUND = 404
CODE_PARAM_INVALIDATE = 400
)
func ErrServerInternal(format string, a ...any) *ApiException {
return &ApiException{
Code: CODE_SERVER_ERROR,
Message: fmt.Sprintf(format, a...),
HttpCode: 500,
}
}
func ErrNotFound(format string, a ...any) *ApiException {
return &ApiException{
Code: CODE_NOT_FOUND,
Message: fmt.Sprintf(format, a...),
HttpCode: 404,
}
}
func ErrValidateFailed(format string, a ...any) *ApiException {
return &ApiException{
Code: CODE_PARAM_INVALIDATE,
Message: fmt.Sprintf(format, a...),
HttpCode: 400,
}
}