This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch dotnet-http-connection
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/dotnet-http-connection by this 
push:
     new 68b2657013 small improvements to response handling
68b2657013 is described below

commit 68b26570133ce4bbe042cbfe3b7ce38617558f1e
Author: Yang Xia <[email protected]>
AuthorDate: Thu Mar 12 13:15:05 2026 -0700

    small improvements to response handling
---
 gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs 
b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index d7b5f119b6..54d53d7815 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -123,6 +123,19 @@ namespace Gremlin.Net.Driver
             using var response = await _httpClient.SendAsync(httpRequest, 
cancellationToken)
                 .ConfigureAwait(false);
 
+            // If the HTTP status indicates an error and the response is not 
GraphBinary
+            // (e.g. a proxy 502 or server 404 returning HTML/plain text), 
fail fast with
+            // a clear message instead of letting the deserializer throw a 
confusing parse error.
+            // When the Content-Type matches GraphBinary, fall through to 
normal deserialization
+            // so the status footer in the GB4 response can surface the 
application-level error.
+            if (!response.IsSuccessStatusCode &&
+                response.Content.Headers.ContentType?.MediaType != 
GraphBinaryMimeType)
+            {
+                var errorBody = await 
response.Content.ReadAsStringAsync().ConfigureAwait(false);
+                throw new HttpRequestException(
+                    $"Gremlin Server returned HTTP {(int)response.StatusCode}: 
{errorBody}");
+            }
+
             var responseBytes = await 
ReadResponseBytesAsync(response).ConfigureAwait(false);
 
             var responseMessage = await 
_serializer.DeserializeMessageAsync(responseBytes, cancellationToken)
@@ -133,7 +146,7 @@ namespace Gremlin.Net.Driver
 
         private static async Task<byte[]> 
ReadResponseBytesAsync(HttpResponseMessage response)
         {
-            var stream = await 
response.Content.ReadAsStreamAsync().ConfigureAwait(false);
+            using var stream = await 
response.Content.ReadAsStreamAsync().ConfigureAwait(false);
             if (response.Content.Headers.ContentEncoding.Contains("deflate"))
             {
                 using var deflateStream = new DeflateStream(stream, 
CompressionMode.Decompress);

Reply via email to