Skip to content

Commit

Permalink
feat: FIR-30193: improved error handling when JSON parsing fails (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexradzin authored Apr 25, 2024
1 parent ab72d73 commit e2491ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions FireboltDotNetSdk.Tests/Unit/FireboltCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public void GetOriginalJsonDataTest()
Assert.False(reader.Read());
}

[Test]
public void GetBadJsonDataTest()
{
string response = "not a json";
var cs = createCommand("select 1", response);
string message = Assert.Throws<FireboltException>(() => cs.ExecuteReader()).Message;
Assert.That(message, Does.Contain("Failed to execute a query"));
}

[TestCase("SET param=1")]
[TestCase("SET param=1,param=2")]
public void ClearSetListTest(string commandText)
Expand Down
11 changes: 9 additions & 2 deletions FireboltNETSDK/Client/FireboltCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,15 @@ private string GetParamValue(object? value)
private QueryResult? GetOriginalJsonData(string? Response)
{
if (Response == null) throw new FireboltException("Response is empty while GetOriginalJSONData");
var prettyJson = JToken.Parse(Response).ToString(Formatting.Indented);
return JsonConvert.DeserializeObject<QueryResult>(prettyJson);
try
{
var prettyJson = JToken.Parse(Response).ToString(Formatting.Indented);
return JsonConvert.DeserializeObject<QueryResult>(prettyJson);
}
catch (JsonReaderException e)
{
throw new FireboltException($"Failed to execute a query. Invalid response body format. Try again or contact support.", e);
}
}

public void ClearSetList()
Expand Down

0 comments on commit e2491ac

Please sign in to comment.