Skip to content

Commit

Permalink
[ISSUE #916] Add message body empty check for C# client
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunghanjacktsai authored Jan 22, 2025
1 parent eeeb643 commit 1f49ca5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
34 changes: 34 additions & 0 deletions csharp/rocketmq-client-csharp/Error/PayloadEmptyException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Org.Apache.Rocketmq.Error
{
/// <summary>
/// Generic exception represents when the request entity is empty.
/// </summary>
public class PayloadEmptyException : ClientException
{
public PayloadEmptyException(int responseCode, string requestId, string message) : base(responseCode,
requestId, message)
{
}

public PayloadEmptyException(int responseCode, string message) : base(responseCode, message)
{
}
}
}
2 changes: 1 addition & 1 deletion csharp/rocketmq-client-csharp/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Builder SetTopic(string topic)

public Builder SetBody(byte[] body)
{
Preconditions.CheckArgument(null != body, "body should not be null");
Preconditions.CheckArgument(null != body || body.Length == 0, "body should not be empty");
_body = body;
return this;
}
Expand Down
2 changes: 2 additions & 0 deletions csharp/rocketmq-client-csharp/StatusChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public static void Check(Proto.Status status, IMessage request, string requestId
case Proto.Code.PayloadTooLarge:
case Proto.Code.MessageBodyTooLarge:
throw new PayloadTooLargeException((int)statusCode, requestId, statusMessage);
case Proto.Code.MessageBodyEmpty:
throw new PayloadEmptyException((int)statusCode, requestId, statusMessage);
case Proto.Code.TooManyRequests:
throw new TooManyRequestsException((int)statusCode, requestId, statusMessage);
case Proto.Code.RequestHeaderFieldsTooLarge:
Expand Down

0 comments on commit 1f49ca5

Please sign in to comment.