friends/grpc/deny_friend_request.go
Daniel López Guimaraes 8d8a05a7e2
Add missing error handling
Now database getters do error handling aswell, and in case of any error,
the NEX or GRPC method throws a proper error about it.

There are still some doubts on how to handle errors when a list of data
is processed, so for now skip that element on the list and continue.

Also add some constant errors to do better error handling.
2023-08-13 23:19:34 +01:00

33 lines
946 B
Go

package grpc
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/PretendoNetwork/friends/database"
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
"github.com/PretendoNetwork/friends/globals"
pb "github.com/PretendoNetwork/grpc-go/friends"
)
func (s *gRPCFriendsServer) DenyFriendRequest(ctx context.Context, in *pb.DenyFriendRequestRequest) (*pb.DenyFriendRequestResponse, error) {
err := database_wiiu.SetFriendRequestDenied(in.GetFriendRequestId())
if err != nil {
if err == database.ErrFriendRequestNotFound {
return &pb.DenyFriendRequestResponse{
Success: false,
}, status.Errorf(codes.NotFound, "friend request not found")
}
globals.Logger.Critical(err.Error())
return &pb.DenyFriendRequestResponse{
Success: false,
}, status.Errorf(codes.Internal, "internal server error")
}
return &pb.DenyFriendRequestResponse{
Success: true,
}, nil
}