fix JSON-RPC response to include 'result' on success even if it's null

This commit is contained in:
Christopher Willis-Ford 2022-05-18 15:05:21 -07:00
parent 35b1973914
commit 0c131d4e5f

View file

@ -387,12 +387,22 @@ internal class Session : IDisposable
private async Task SendResponse(object id, object result, JsonRpc2Error error, CancellationToken cancellationToken)
{
var response = new JsonRpc2Response
var response = new JsonRpc2Message
{
Id = id,
Result = (error == null) ? result : null,
Error = error,
ExtraProperties = new (),
};
// handling "result" this way, instead of using JsonRpc2Response, means we can send "result: null" iff both result and error are null
if (error == null)
{
response.ExtraProperties["result"] = result;
}
else
{
response.ExtraProperties["error"] = error;
}
var responseBytes = JsonSerializer.SerializeToUtf8Bytes(response);
await this.SocketSend(responseBytes, cancellationToken);