| 
					
				 | 
			
			
				@@ -15,6 +15,7 @@ namespace InABox.Rpc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private RpcClientSession _session = new RpcClientSession(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private ConcurrentDictionary<Guid, ManualResetEventSlim> _events = new ConcurrentDictionary<Guid, ManualResetEventSlim>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private ConcurrentDictionary<Guid, RpcMessage> _responses = new ConcurrentDictionary<Guid, RpcMessage>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private ConcurrentDictionary<Guid, Exception> _exceptions = new ConcurrentDictionary<Guid, Exception>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private const int DefaultRequestTimeout = 5 * 60 * 1000; // 5 minutes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -45,6 +46,16 @@ namespace InABox.Rpc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public abstract void Send(RpcMessage message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public void Fail(RpcMessage message, Exception e) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CoreUtils.LogException("", e, "Message Failed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(_events.TryGetValue(message.Id, out var ev)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                _exceptions[message.Id] = e; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ev.Set(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public void Accept(RpcMessage? message) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (message == null) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -89,8 +100,12 @@ namespace InABox.Rpc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Send(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var response = GetResponse(request.Id, ev, DefaultRequestTimeout) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var response = GetResponse(request.Id, ev, DefaultRequestTimeout, out var e) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ?? throw new Exception($"{typeof(TCommand).Name}({request.Id}) returned NULL"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(e != null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw e; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             switch (response.Error) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -126,11 +141,19 @@ namespace InABox.Rpc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ev; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public RpcMessage? GetResponse(Guid id, ManualResetEventSlim ev, int timeout) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public RpcMessage? GetResponse(Guid id, ManualResetEventSlim ev, int timeout, out Exception? error) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            error = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (_responses.TryGetValue(id, out var response)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 _responses.Remove(id, out response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                _exceptions.Remove(id, out var _e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                _events.Remove(id, out ev); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return response; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(_exceptions.TryGetValue(id, out error)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                _exceptions.Remove(id, out error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 _events.Remove(id, out ev); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return response; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -149,6 +172,7 @@ namespace InABox.Rpc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _responses.Remove(id, out response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            _exceptions.Remove(id, out error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _events.Remove(id, out ev); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response ?? new RpcMessage() { Error = RpcError.UNKNOWN }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |