2024-02-11 01:31:01 +08:00
|
|
|
package exception
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// google grpc error status.
|
2024-02-20 14:55:45 +08:00
|
|
|
OK = Errorf(0, "OK")
|
|
|
|
ErrCanceled = Errorf(1, "Canceled")
|
|
|
|
ErrUnknown = Errorf(2, "Unknown")
|
|
|
|
ErrInvalidArgument = Errorf(3, "Invalid Argument")
|
|
|
|
ErrDeadlineExceeded = Errorf(4, "Deadline Exceeded")
|
|
|
|
ErrNotFound = Errorf(5, "Not Found")
|
|
|
|
ErrAlreadyExists = Errorf(6, "Already Exists")
|
|
|
|
ErrPermissionDenied = Errorf(7, "Permission Denied")
|
|
|
|
ErrResourceExhausted = Errorf(8, "Resource Exhausted")
|
|
|
|
ErrFailedPrecondition = Errorf(9, "Failed Precondition")
|
|
|
|
ErrAborted = Errorf(10, "Aborted")
|
|
|
|
ErrOutOfRange = Errorf(11, "Out Of Range")
|
|
|
|
ErrUnimplemented = Errorf(12, "Unimplemented")
|
|
|
|
ErrInternal = Errorf(13, "Internal")
|
|
|
|
ErrUnavailable = Errorf(14, "Unavailable")
|
|
|
|
ErrDataLoss = Errorf(15, "Data Loss")
|
|
|
|
ErrUnauthenticated = Errorf(16, "Unauthenticated")
|
|
|
|
ErrJSONMarshal = Errorf(17, "Marshal JSON")
|
|
|
|
ErrJSONUnmarshal = Errorf(18, "Unmarshal JSON")
|
2024-02-28 13:40:34 +08:00
|
|
|
ErrPasswd = Errorf(19, "Password Error")
|
2024-02-20 14:55:45 +08:00
|
|
|
|
2024-06-05 15:46:57 +08:00
|
|
|
ErrSmsCode = Errorf(20, "SMS Code Invalid")
|
|
|
|
ErrIdArgument = Errorf(30, "ID Invalid Argument")
|
|
|
|
ErrIdentityArgument = Errorf(31, "Identity Invalid Argument")
|
2024-02-11 01:31:01 +08:00
|
|
|
|
|
|
|
// coustom error status
|
|
|
|
)
|
|
|
|
|
|
|
|
func Error(c uint32, msg string) error {
|
|
|
|
return status.New(codes.Code(c), msg).Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
func Errorf(c uint32, format string, a ...interface{}) error {
|
|
|
|
return status.New(codes.Code(c), fmt.Sprintf(format, a...)).Err()
|
|
|
|
}
|