rf/normalizes error responses
This commit is contained in:
		
							parent
							
								
									86b10b8d12
								
							
						
					
					
						commit
						ade7be7f1b
					
				| @ -48,7 +48,7 @@ func (server *Server) CreateAccount(ctx context.Context, req *pb.CreateAccountRe | |||||||
| 
 | 
 | ||||||
| 	account, err := server.store.CreateAccountTx(ctx, arg) | 	account, err := server.store.CreateAccountTx(ctx, arg) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, status.Errorf(codes.Internal, "failed to create account: %s", err) | 		return nil, status.Error(codes.Internal, "failed to create account") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	rsp := &pb.CreateAccountResponse{ | 	rsp := &pb.CreateAccountResponse{ | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package gapi | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"database/sql" | ||||||
| 	"errors" | 	"errors" | ||||||
| 
 | 
 | ||||||
| 	db "github.com/itsscb/df/bff/db/sqlc" | 	db "github.com/itsscb/df/bff/db/sqlc" | ||||||
| @ -25,6 +26,9 @@ func (server *Server) CreatePerson(ctx context.Context, req *pb.CreatePersonRequ | |||||||
| 
 | 
 | ||||||
| 	account, err := server.store.GetAccount(ctx, req.GetAccountId()) | 	account, err := server.store.GetAccount(ctx, req.GetAccountId()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		if errors.Is(err, sql.ErrNoRows) { | ||||||
|  | 			return nil, status.Errorf(codes.NotFound, "account not found") | ||||||
|  | 		} | ||||||
| 		return nil, status.Error(codes.NotFound, "failed to get account") | 		return nil, status.Error(codes.NotFound, "failed to get account") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -49,7 +53,7 @@ func (server *Server) CreatePerson(ctx context.Context, req *pb.CreatePersonRequ | |||||||
| 
 | 
 | ||||||
| 	person, err := server.store.CreatePersonTx(ctx, arg) | 	person, err := server.store.CreatePersonTx(ctx, arg) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, status.Errorf(codes.Internal, "failed to create person: %s", err) | 		return nil, status.Errorf(codes.Internal, "failed to create person") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	rsp := &pb.CreatePersonResponse{ | 	rsp := &pb.CreatePersonResponse{ | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package gapi | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"database/sql" | ||||||
| 	"errors" | 	"errors" | ||||||
| 
 | 
 | ||||||
| 	"github.com/itsscb/df/bff/pb" | 	"github.com/itsscb/df/bff/pb" | ||||||
| @ -23,7 +24,10 @@ func (server *Server) GetAccount(ctx context.Context, req *pb.GetAccountRequest) | |||||||
| 
 | 
 | ||||||
| 	account, err := server.store.GetAccount(ctx, req.GetId()) | 	account, err := server.store.GetAccount(ctx, req.GetId()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, status.Error(codes.NotFound, "failed to get account") | 		if errors.Is(err, sql.ErrNoRows) { | ||||||
|  | 			return nil, status.Errorf(codes.NotFound, "account not found") | ||||||
|  | 		} | ||||||
|  | 		return nil, status.Error(codes.Internal, "failed to get account") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if authPayload.Email != account.Email { | 	if authPayload.Email != account.Email { | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package gapi | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"database/sql" | ||||||
| 	"errors" | 	"errors" | ||||||
| 
 | 
 | ||||||
| 	db "github.com/itsscb/df/bff/db/sqlc" | 	db "github.com/itsscb/df/bff/db/sqlc" | ||||||
| @ -29,7 +30,10 @@ func (server *Server) ListAccounts(ctx context.Context, req *pb.ListAccountsRequ | |||||||
| 
 | 
 | ||||||
| 	dbAccounts, err := server.store.ListAccounts(ctx, arg) | 	dbAccounts, err := server.store.ListAccounts(ctx, arg) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, status.Error(codes.NotFound, "failed to get account") | 		if errors.Is(err, sql.ErrNoRows) { | ||||||
|  | 			return nil, status.Error(codes.NotFound, "no accounts found") | ||||||
|  | 		} | ||||||
|  | 		return nil, status.Error(codes.NotFound, "failed to get accounts") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if !server.isAdmin(ctx, authPayload) { | 	if !server.isAdmin(ctx, authPayload) { | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ func (server *Server) Login(ctx context.Context, req *pb.LoginRequest) (*pb.Logi | |||||||
| 			return nil, status.Error(codes.NotFound, "account not found") | 			return nil, status.Error(codes.NotFound, "account not found") | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 		return nil, status.Error(codes.Internal, "failed to find account") | 		return nil, status.Error(codes.Internal, "failed to get account") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err = util.CheckPassword(req.GetPassword(), account.Passwordhash) | 	err = util.CheckPassword(req.GetPassword(), account.Passwordhash) | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ func (server *Server) UpdateAccount(ctx context.Context, req *pb.UpdateAccountRe | |||||||
| 		return nil, invalidArgumentError(violations) | 		return nil, invalidArgumentError(violations) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if authPayload.Email != req.GetEmail() && !server.isAdmin(ctx, authPayload) { | 	if authPayload.Email != req.GetEmail() { | ||||||
| 		if !server.isAdmin(ctx, authPayload) { | 		if !server.isAdmin(ctx, authPayload) { | ||||||
| 			return nil, status.Error(codes.NotFound, "account not found") | 			return nil, status.Error(codes.NotFound, "account not found") | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user