|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using InABox.Clients;
|
|
@@ -92,12 +93,19 @@ namespace InABox.Rpc
|
|
|
var response = GetResponse(request.Id, ev, DefaultRequestTimeout)
|
|
|
?? throw new Exception($"{typeof(TCommand).Name}({request.Id}) returned NULL");
|
|
|
|
|
|
- if (response.Error != RpcError.NONE) throw new RpcException($"Server error in {typeof(TCommand).Name}({request.Id}): {response.Error}", response.Error);
|
|
|
-
|
|
|
- var result = Serialization.ReadBinary<TResult>(response.Payload, BinarySerializationSettings.Latest)
|
|
|
- ?? throw new Exception($"Cannot Deserialize {typeof(TCommand).Name}({request.Id})");
|
|
|
-
|
|
|
- return result;
|
|
|
+ switch (response.Error)
|
|
|
+ {
|
|
|
+ case RpcError.NONE:
|
|
|
+ var result = Serialization.ReadBinary<TResult>(response.Payload, BinarySerializationSettings.Latest)
|
|
|
+ ?? throw new Exception($"Cannot Deserialize {typeof(TCommand).Name}({request.Id})");
|
|
|
+
|
|
|
+ return result;
|
|
|
+ case RpcError.SERVERERROR:
|
|
|
+ var errorMessage = Encoding.UTF8.GetString(response.Payload);
|
|
|
+ throw new RpcException(errorMessage, response.Error);
|
|
|
+ default:
|
|
|
+ throw new RpcException($"Server error in {typeof(TCommand).Name}({request.Id}): {response.Error}", response.Error);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void CheckConnection<TCommand, TParameters, TResult>() where TCommand : IRpcCommand<TParameters, TResult>
|