mirror of
https://github.com/scratchfoundation/scratch-link.git
synced 2025-08-28 22:39:42 -04:00
correctly handle null Result in a Response
This commit is contained in:
parent
9ccdabb64d
commit
d1bff9b2c7
3 changed files with 7 additions and 13 deletions
|
@ -36,25 +36,19 @@ internal class JsonRpc2MessageConverter : JsonConverter<JsonRpc2Message>
|
|||
/// <inheritdoc/>
|
||||
public override void Write(Utf8JsonWriter writer, JsonRpc2Message value, JsonSerializerOptions options) => JsonSerializer.Serialize(writer, value, options);
|
||||
|
||||
private class MessageTypeDiscriminator
|
||||
private class MessageTypeDiscriminator : JsonRpc2Message
|
||||
{
|
||||
[JsonPropertyName("method")]
|
||||
public string Method { get; set; }
|
||||
|
||||
[JsonPropertyName("result")]
|
||||
public object Result { get; set; }
|
||||
|
||||
[JsonPropertyName("error")]
|
||||
public JsonRpc2Error Error { get; set; }
|
||||
|
||||
public Type GuessMessageType()
|
||||
{
|
||||
if (this.Result != null || this.Error != null)
|
||||
if (this.Error != null || this.ExtraProperties.ContainsKey("result"))
|
||||
{
|
||||
return typeof(JsonRpc2Response);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Method))
|
||||
if (this.ExtraProperties.ContainsKey("method"))
|
||||
{
|
||||
return typeof(JsonRpc2Request);
|
||||
}
|
||||
|
|
|
@ -36,11 +36,11 @@ internal class JsonRpc2Message
|
|||
public object Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary to contain additional properties not part of the static C# type.
|
||||
/// Gets or sets a dictionary to contain additional properties not part of the static C# type.
|
||||
/// </summary>
|
||||
[JsonExtensionData]
|
||||
[JsonPropertyOrder(100)]
|
||||
public Dictionary<string, object> ExtraProperties { get; } = new ();
|
||||
public Dictionary<string, object> ExtraProperties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not this is a valid JSON-RPC message.
|
||||
|
|
|
@ -402,11 +402,11 @@ internal class Session : IDisposable
|
|||
{
|
||||
if (error != null)
|
||||
{
|
||||
this.completionSource.SetException(new JsonRpc2Exception(error));
|
||||
this.completionSource.TrySetException(new JsonRpc2Exception(error));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.completionSource.SetResult(result);
|
||||
this.completionSource.TrySetResult(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue