add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m24s
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m24s
This commit is contained in:
@@ -6,6 +6,8 @@ const (
|
||||
AuthInvalidToken = "AUTH_INVALID_TOKEN"
|
||||
RefreshInvalid = "REFRESH_INVALID"
|
||||
InviteLimitReached = "INVITE_LIMIT_REACHED"
|
||||
InviteInvalidOrExpired = "INVITE_INVALID_OR_EXPIRED"
|
||||
EmailAlreadyExists = "EMAIL_ALREADY_EXISTS"
|
||||
InsufficientBalance = "INSUFFICIENT_BALANCE"
|
||||
UserNotFound = "USER_NOT_FOUND"
|
||||
RequestNotFound = "REQUEST_NOT_FOUND"
|
||||
|
||||
@@ -51,6 +51,14 @@ func NewInternalError(code, message string, err error) *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
func IsBusinessError(err error, code string) bool {
|
||||
var appErr *AppError
|
||||
if !errors.As(err, &appErr) {
|
||||
return false
|
||||
}
|
||||
return appErr.Type == BusinessError && appErr.Code == code
|
||||
}
|
||||
|
||||
func ToGRPCError(err error, zapLogger *zap.Logger, method string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
@@ -85,8 +93,10 @@ func ToGRPCError(err error, zapLogger *zap.Logger, method string) error {
|
||||
return status.Error(codes.Unauthenticated, appErr.Message)
|
||||
case InviteLimitReached:
|
||||
return status.Error(codes.ResourceExhausted, appErr.Message)
|
||||
case InsufficientBalance:
|
||||
case InsufficientBalance, InviteInvalidOrExpired:
|
||||
return status.Error(codes.FailedPrecondition, appErr.Message)
|
||||
case EmailAlreadyExists:
|
||||
return status.Error(codes.AlreadyExists, appErr.Message)
|
||||
case UserNotFound, RequestNotFound:
|
||||
return status.Error(codes.NotFound, appErr.Message)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user