Skip to content

Commit 7455690

Browse files
Added new exception RpcErrorException to allow you to return a specific code and error object back to the other side
1 parent 9e468e0 commit 7455690

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/JsonRpc/RequestRouterBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public virtual async Task<ErrorResponse> RouteRequest(TDescriptor descriptor, Re
153153
_logger.LogDebug("Request {Id} was cancelled", id);
154154
return new RequestCancelled();
155155
}
156+
catch (RpcErrorException e)
157+
{
158+
_logger.LogCritical(Events.UnhandledRequest, e, "Failed to handle notification {Method}", request.Method);
159+
return new RpcError(id, new ErrorMessage(e.Code, e.Message, e.Error));
160+
}
156161
catch (Exception e)
157162
{
158163
_logger.LogCritical(Events.UnhandledRequest, e, "Failed to handle notification {Method}", request.Method);

src/JsonRpc/RpcErrorException.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace OmniSharp.Extensions.JsonRpc
4+
{
5+
public class RpcErrorException : Exception
6+
{
7+
public RpcErrorException(int code, object error)
8+
{
9+
Error = error;
10+
Code = code;
11+
}
12+
13+
public RpcErrorException(int code, object error, string message) : base(message)
14+
{
15+
Error = error;
16+
Code = code;
17+
}
18+
19+
public object Error { get; }
20+
public int Code { get; }
21+
}
22+
}

0 commit comments

Comments
 (0)