From 18d552b36c68398be63a089d8a7887a15899ce15 Mon Sep 17 00:00:00 2001 From: creeppak Date: Tue, 3 Sep 2024 15:12:37 +0100 Subject: [PATCH 1/2] Added another assert statement to throw a different message when there is connection error in UnityHttpClient.cs --- src/ChainSafe.Gaming.Unity/UnityHttpClient.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs b/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs index 0cf279fc4..5a9f63972 100644 --- a/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs +++ b/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs @@ -32,11 +32,20 @@ public UnityHttpClient(IMainThreadRunner mainThreadRunner) /// Converted Network Response. private static NetworkResponse UnityWebRequestToNetworkResponse(UnityWebRequest request) { - Assert.AreNotEqual(request.result, UnityWebRequest.Result.InProgress); - - if (request.result != UnityWebRequest.Result.Success) + // Assert response is successful { - throw new Web3Exception($"HTTP.{request.method} to {request.url} responded with error: {request.downloadHandler.text}"); + Assert.AreNotEqual(UnityWebRequest.Result.InProgress, request.result); + + if (request.result == UnityWebRequest.Result.ConnectionError) + { + throw new Web3Exception($"HTTP.{request.method} to {request.url} - connection error."); + } + + if (request.result != UnityWebRequest.Result.Success) + { + throw new Web3Exception( + $"HTTP.{request.method} to {request.url} responded with error: {request.downloadHandler.text}"); + } } return NetworkResponse.Success(request.downloadHandler.text); From 4a60d041bc515482770f6107a59f2117f1af5c9b Mon Sep 17 00:00:00 2001 From: creeppak Date: Tue, 3 Sep 2024 15:30:20 +0100 Subject: [PATCH 2/2] Slightly updated the exception message format. --- src/ChainSafe.Gaming.Unity/UnityHttpClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs b/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs index 5a9f63972..95c7b1f78 100644 --- a/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs +++ b/src/ChainSafe.Gaming.Unity/UnityHttpClient.cs @@ -38,13 +38,13 @@ private static NetworkResponse UnityWebRequestToNetworkResponse(UnityWeb if (request.result == UnityWebRequest.Result.ConnectionError) { - throw new Web3Exception($"HTTP.{request.method} to {request.url} - connection error."); + throw new Web3Exception($"HTTP.{request.method} to '{request.url}' - connection error."); } if (request.result != UnityWebRequest.Result.Success) { throw new Web3Exception( - $"HTTP.{request.method} to {request.url} responded with error: {request.downloadHandler.text}"); + $"HTTP.{request.method} to '{request.url}' responded with error: {request.downloadHandler.text}"); } }