From 6729bd428538f0befaa7cefe145a413a796d946e Mon Sep 17 00:00:00 2001 From: James <539129+jamesrom@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:06:34 +1100 Subject: [PATCH] Alternative fix: keep back compat with interceptor contract --- client.go | 4 ++-- client_error_handling_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 3fe59755..53d765d5 100644 --- a/client.go +++ b/client.go @@ -95,7 +95,7 @@ func NewClient[Req, Res any](httpClient HTTPClient, url string, options ...Clien response, err := receiveUnaryResponse[Res](conn, config.Initializer) if err != nil { _ = conn.CloseResponse() - return response, err + return nil, err } return response, conn.CloseResponse() }) @@ -110,7 +110,7 @@ func NewClient[Req, Res any](httpClient HTTPClient, url string, options ...Clien request.peer = client.protocolClient.Peer() protocolClient.WriteRequestHeader(StreamTypeUnary, request.Header()) response, err := unaryFunc(ctx, request) - if err != nil { + if err != nil || response == nil { return nil, err } typed, ok := response.(*Response[Res]) diff --git a/client_error_handling_test.go b/client_error_handling_test.go index c9659e9d..d3e5f9db 100644 --- a/client_error_handling_test.go +++ b/client_error_handling_test.go @@ -53,7 +53,7 @@ func TestClientErrorHandling(t *testing.T) { // errorHidingInterceptor is a simple interceptor that hides errors based on // some criteria (in this case, if the error is a CodeCanceled error). It is -// use to reproduce an issue with error handling in the client, where the +// used to reproduce an issue with error handling in the client, where the // type information is lost between unaryFunc and client.callUnary. type errorHidingInterceptor struct{}