From 28d8eb5263c46361e76be09708451cd91a128e36 Mon Sep 17 00:00:00 2001 From: Ryan Sweet Date: Fri, 15 Nov 2024 13:38:22 -0800 Subject: [PATCH] add error handling for requests --- .../Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs b/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs index cb9a00be7492..0bd35b2b25cd 100644 --- a/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs +++ b/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs @@ -110,9 +110,15 @@ internal async Task OnReceivedMessageAsync(GrpcWorkerConnection connection, Mess await AddSubscriptionAsync(connection, message.AddSubscriptionRequest); break; default: - throw new InvalidOperationException($"Unknown message type for message '{message}'."); + // if it wasn't recognized return bad request + await RespondBadRequestAsync(connection, message.RequestId, $"Unknown message type for message '{message}'."); + break; }; } + private async ValueTask RespondBadRequestAsync(GrpcWorkerConnection connection, string requestId, string error) + { + throw new RpcException(new Status(StatusCode.InvalidArgument, error)); + } private async ValueTask AddSubscriptionAsync(GrpcWorkerConnection connection, AddSubscriptionRequest request) { var topic = request.Subscription.TypeSubscription.TopicType;