mirror of
https://github.com/scratchfoundation/scratch-link.git
synced 2025-08-28 22:39:42 -04:00
fix JSON-RPC response to include 'result' on success even if it's null
This commit is contained in:
parent
35b1973914
commit
0c131d4e5f
1 changed files with 13 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue