Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dotnet/src/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ private void HandleResponse(JsonElement message, JsonElement idProp)
var errorCode = errorProp.TryGetProperty("code", out var codeProp) && codeProp.ValueKind == JsonValueKind.Number
? codeProp.GetInt32()
: 0;
pending.TrySetException(new RemoteRpcException(errorMessage, errorCode));
var errorData = errorProp.TryGetProperty("data", out var dataProp)
? dataProp.Clone()
: (JsonElement?)null;
pending.TrySetException(new RemoteRpcException(errorMessage, errorCode, errorData));
Comment on lines +443 to +446
}
else if (message.TryGetProperty("result", out var resultProp))
{
Expand Down Expand Up @@ -899,12 +902,14 @@ internal sealed class ConnectionLostException() : IOException("The JSON-RPC conn
/// <summary>
/// Thrown when the remote side returns a JSON-RPC error response.
/// </summary>
internal sealed class RemoteRpcException(string message, int errorCode, Exception? innerException = null) : Exception(message, innerException)
internal sealed class RemoteRpcException(string message, int errorCode, JsonElement? errorData = null, Exception? innerException = null) : Exception(message, innerException)
{
/// <summary>JSON-RPC 2.0 reserved error code: requested method does not exist.</summary>
public const int MethodNotFoundErrorCode = -32601;

public int ErrorCode { get; } = errorCode;

public JsonElement? ErrorData { get; } = errorData.HasValue ? errorData.Value.Clone() : null;
}

/// <summary>
Expand Down
Loading