I have a grpc handler Something(ctx context.Context, request *protocol.Something) (*pb.Test, error)
I return errors like return nil, status.Error(codes.InvalidArgument, "something wrong")
In case of success. I always return nil return test, nil
, although there is code 0
. Do I have to return the code on success? return test, status.New(codes.OK, "OK")
CodePudding user response:
Per doc - return code 0
means not an error; returned on success.
Code | Number | Description |
---|---|---|
OK | 0 | Not an error; returned on success. |
Through return test, nil
, the nil in the error, means there is no error, and OK
is returned on success
// OK is returned on success.
OK Code = 0
CodePudding user response:
No you don't need to do that - no need to return the status code ok on success