Return correct errors in public accounts service

Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
2026-06-10 16:02:23 +02:00
parent 6e5e0fc805
commit 64db382546
2 changed files with 130 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package v1
import (
"context"
"errors"
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/services"
accounts "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
@@ -28,6 +29,9 @@ type PublicAccountService struct {
func (a *PublicAccountService) SignIn(ctx context.Context, in *accounts.SignInRequest) (*accounts.SignInResponse, error) {
id, err := a.accountsCtrl.Login(ctx, in.GetEmail(), in.GetPassword())
if err != nil {
if errors.Is(err, services.ErrUserNotFound) {
return nil, status.Error(codes.NotFound, "User not found")
}
return nil, status.Error(codes.Aborted, "Couldn't create a user")
}
accessToken, _, err := a.authorizationCtrl.GenerateToken(&services.JWTData{
@@ -71,6 +75,9 @@ func (a *PublicAccountService) SignUp(ctx context.Context, in *accounts.SignUpRe
}
id, err := a.accountsCtrl.Create(ctx, data)
if err != nil {
if errors.Is(err, services.ErrEmailUsed) {
return nil, status.Error(codes.AlreadyExists, "Email is already used by another account")
}
return nil, status.Error(codes.Aborted, "Couldn't create a user")
}