Skip to content

Commit 1f49ca5

Browse files
[ISSUE #916] Add message body empty check for C# client
1 parent eeeb643 commit 1f49ca5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Org.Apache.Rocketmq.Error
19+
{
20+
/// <summary>
21+
/// Generic exception represents when the request entity is empty.
22+
/// </summary>
23+
public class PayloadEmptyException : ClientException
24+
{
25+
public PayloadEmptyException(int responseCode, string requestId, string message) : base(responseCode,
26+
requestId, message)
27+
{
28+
}
29+
30+
public PayloadEmptyException(int responseCode, string message) : base(responseCode, message)
31+
{
32+
}
33+
}
34+
}

csharp/rocketmq-client-csharp/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Builder SetTopic(string topic)
9191

9292
public Builder SetBody(byte[] body)
9393
{
94-
Preconditions.CheckArgument(null != body, "body should not be null");
94+
Preconditions.CheckArgument(null != body || body.Length == 0, "body should not be empty");
9595
_body = body;
9696
return this;
9797
}

csharp/rocketmq-client-csharp/StatusChecker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static void Check(Proto.Status status, IMessage request, string requestId
7777
case Proto.Code.PayloadTooLarge:
7878
case Proto.Code.MessageBodyTooLarge:
7979
throw new PayloadTooLargeException((int)statusCode, requestId, statusMessage);
80+
case Proto.Code.MessageBodyEmpty:
81+
throw new PayloadEmptyException((int)statusCode, requestId, statusMessage);
8082
case Proto.Code.TooManyRequests:
8183
throw new TooManyRequestsException((int)statusCode, requestId, statusMessage);
8284
case Proto.Code.RequestHeaderFieldsTooLarge:

0 commit comments

Comments
 (0)