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;