Skip to content

Commit

Permalink
add error handling for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rysweet committed Nov 15, 2024
1 parent 42ccad3 commit 28d8eb5
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 28d8eb5

Please sign in to comment.