Skip to content

Commit df8f761

Browse files
committed
remove exceptions from cg methods
1 parent 55edb60 commit df8f761

3 files changed

Lines changed: 53 additions & 24 deletions

File tree

‎java/srcPubnubApi/com/pubnub/api/PubnubCore.java‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,11 +1186,18 @@ public void handleError(HttpRequest hreq, PubnubError error) {
11861186
* @param group name
11871187
* @param callback to invoke
11881188
*/
1189-
public void channelGroupListChannels(String group, Callback callback) throws PubnubException {
1189+
public void channelGroupListChannels(String group, Callback callback) {
11901190
final Callback cb = getWrappedCallback(callback);
1191-
ChannelGroup channelGroup = new ChannelGroup(group);
1191+
ChannelGroup channelGroup;
11921192
String[] url;
11931193

1194+
try {
1195+
channelGroup = new ChannelGroup(group);
1196+
} catch (PubnubException e) {
1197+
cb.errorCallback(null, PubnubError.PNERROBJ_CHANNEL_GROUP_PARSING_ERROR);
1198+
return;
1199+
}
1200+
11941201
if (channelGroup.namespace != null) {
11951202
url = new String[]{getPubnubUrl(), "v1", "channel-registration", "sub-key",
11961203
this.SUBSCRIBE_KEY, "namespace", channelGroup.namespace, "channel-group", channelGroup.group};
@@ -1215,28 +1222,34 @@ public void handleError(HttpRequest hreq, PubnubError error) {
12151222
_request(hreq, nonSubscribeManager);
12161223
}
12171224

1218-
public void channelGroupAddChannel(String group, String channel, Callback callback) throws PubnubException {
1225+
public void channelGroupAddChannel(String group, String channel, Callback callback) {
12191226
channelGroupUpdate("add", group, new String[]{channel}, callback);
12201227
}
12211228

1222-
public void channelGroupAddChannel(String group, String[] channels, Callback callback) throws PubnubException {
1229+
public void channelGroupAddChannel(String group, String[] channels, Callback callback) {
12231230
channelGroupUpdate("add", group, channels, callback);
12241231
}
12251232

1226-
public void channelGroupRemoveChannel(String group, String channel, Callback callback) throws PubnubException {
1233+
public void channelGroupRemoveChannel(String group, String channel, Callback callback) {
12271234
channelGroupUpdate("remove", group, new String[]{channel}, callback);
12281235
}
12291236

1230-
public void channelGroupRemoveChannel(String group, String[] channels, Callback callback) throws PubnubException {
1237+
public void channelGroupRemoveChannel(String group, String[] channels, Callback callback) {
12311238
channelGroupUpdate("remove", group, channels, callback);
12321239
}
12331240

1234-
public void channelGroupUpdate(String action, String group,
1235-
String[] channels, final Callback callback) throws PubnubException {
1241+
public void channelGroupUpdate(String action, String group, String[] channels, final Callback callback) {
12361242
final Callback cb = getWrappedCallback(callback);
1237-
ChannelGroup channelGroup = new ChannelGroup(group);
1243+
ChannelGroup channelGroup;
12381244
String[] url;
12391245

1246+
try {
1247+
channelGroup = new ChannelGroup(group);
1248+
} catch (PubnubException e) {
1249+
cb.errorCallback(null, PubnubError.PNERROBJ_CHANNEL_GROUP_PARSING_ERROR);
1250+
return;
1251+
}
1252+
12401253
if (channelGroup.namespace != null) {
12411254
url = new String[]{getPubnubUrl(), "v1", "channel-registration", "sub-key",
12421255
this.SUBSCRIBE_KEY, "namespace", channelGroup.namespace, "channel-group", channelGroup.group};
@@ -1266,11 +1279,18 @@ public void handleError(HttpRequest hreq, PubnubError error) {
12661279
_request(hreq, nonSubscribeManager);
12671280
}
12681281

1269-
public void channelGroupRemoveGroup(String group, Callback callback) throws PubnubException {
1282+
public void channelGroupRemoveGroup(String group, Callback callback) {
12701283
final Callback cb = getWrappedCallback(callback);
1271-
ChannelGroup channelGroup = new ChannelGroup(group);
1284+
ChannelGroup channelGroup;
12721285
String[] url;
12731286

1287+
try {
1288+
channelGroup = new ChannelGroup(group);
1289+
} catch (PubnubException e) {
1290+
cb.errorCallback(null, PubnubError.PNERROBJ_CHANNEL_GROUP_PARSING_ERROR);
1291+
return;
1292+
}
1293+
12741294
if (channelGroup.namespace != null) {
12751295
url = new String[]{getPubnubUrl(), "v1", "channel-registration", "sub-key",
12761296
this.SUBSCRIBE_KEY, "namespace",

‎java/srcPubnubApi/com/pubnub/api/PubnubError.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ public class PubnubError {
208208
*/
209209
public static final int PNERR_CONNECTION_NOT_SET = 133;
210210

211+
/**
212+
* Error while parsing group name
213+
*/
214+
public static final int PNERR_CHANNEL_GROUP_PARSING_ERROR = 134;
211215
// Error Objects
212216

213217
static final PubnubError PNERROBJ_TIMEOUT =
@@ -433,6 +437,11 @@ public class PubnubError {
433437
"Pubnub Connection not set"
434438
);
435439

440+
static final PubnubError PNERROBJ_CHANNEL_GROUP_PARSING_ERROR =
441+
new PubnubError (
442+
PNERR_CHANNEL_GROUP_PARSING_ERROR ,
443+
"Channel group name is invalid"
444+
);
436445

437446
public final int errorCode;
438447
public final int errorCodeExtended;

‎java/srcTest/com/pubnub/api/ChannelGroupTest.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void setUp() {
2929
}
3030

3131
@Test
32-
public void testAddChannelToNonNameSpacedGroup() throws PubnubException {
32+
public void testAddChannelToNonNameSpacedGroup() {
3333
final CountDownLatch latch = new CountDownLatch(1);
3434

3535
final TestHelper.SimpleCallback cb = new TestHelper.SimpleCallback(latch) {
@@ -48,7 +48,7 @@ public void testAddChannelToNonNameSpacedGroup() throws PubnubException {
4848
}
4949

5050
@Test
51-
public void testAddChannelToNameSpacedGroup() throws PubnubException {
51+
public void testAddChannelToNameSpacedGroup() {
5252
final CountDownLatch latch = new CountDownLatch(1);
5353

5454
final TestHelper.SimpleCallback cb = new TestHelper.SimpleCallback(latch) {
@@ -67,7 +67,7 @@ public void testAddChannelToNameSpacedGroup() throws PubnubException {
6767
}
6868

6969
@Test
70-
public void testAddChannelsToNonNameSpacedGroup() throws PubnubException {
70+
public void testAddChannelsToNonNameSpacedGroup() {
7171
final CountDownLatch latch = new CountDownLatch(1);
7272

7373
final TestHelper.SimpleCallback cb = new TestHelper.SimpleCallback(latch) {
@@ -86,7 +86,7 @@ public void testAddChannelsToNonNameSpacedGroup() throws PubnubException {
8686
}
8787

8888
@Test
89-
public void testAddChannelsToNameSpacedGroup() throws PubnubException {
89+
public void testAddChannelsToNameSpacedGroup() {
9090
final CountDownLatch latch = new CountDownLatch(1);
9191

9292
final TestHelper.SimpleCallback cb = new TestHelper.SimpleCallback(latch) {
@@ -105,7 +105,7 @@ public void testAddChannelsToNameSpacedGroup() throws PubnubException {
105105
}
106106

107107
@Test
108-
public void testGetChannelsOnNonNameSpacedGroup() throws InterruptedException, JSONException, PubnubException {
108+
public void testGetChannelsOnNonNameSpacedGroup() throws InterruptedException, JSONException {
109109
final CountDownLatch latch1 = new CountDownLatch(1);
110110
final CountDownLatch latch2 = new CountDownLatch(1);
111111
final CountDownLatch latch3 = new CountDownLatch(1);
@@ -139,7 +139,7 @@ public void testGetChannelsOnNonNameSpacedGroup() throws InterruptedException, J
139139
}
140140

141141
@Test
142-
public void testGetChannelsOnNameSpacedGroup() throws InterruptedException, JSONException, PubnubException {
142+
public void testGetChannelsOnNameSpacedGroup() throws InterruptedException, JSONException {
143143
final CountDownLatch latch1 = new CountDownLatch(1);
144144
final CountDownLatch latch2 = new CountDownLatch(1);
145145
final CountDownLatch latch3 = new CountDownLatch(1);
@@ -173,7 +173,7 @@ public void testGetChannelsOnNameSpacedGroup() throws InterruptedException, JSON
173173
}
174174

175175
@Test
176-
public void testRemoveChannelsFromNonNameSpacedGroup() throws InterruptedException, JSONException, PubnubException {
176+
public void testRemoveChannelsFromNonNameSpacedGroup() throws InterruptedException, JSONException {
177177
final CountDownLatch latch1 = new CountDownLatch(1);
178178
final CountDownLatch latch2 = new CountDownLatch(1);
179179
final CountDownLatch latch3 = new CountDownLatch(1);
@@ -214,7 +214,7 @@ public void testRemoveChannelsFromNonNameSpacedGroup() throws InterruptedExcepti
214214
}
215215

216216
@Test
217-
public void testRemoveChannelsFromNameSpacedGroup() throws InterruptedException, JSONException, PubnubException {
217+
public void testRemoveChannelsFromNameSpacedGroup() throws InterruptedException, JSONException {
218218
final CountDownLatch latch1 = new CountDownLatch(1);
219219
final CountDownLatch latch2 = new CountDownLatch(1);
220220
final CountDownLatch latch3 = new CountDownLatch(1);
@@ -255,7 +255,7 @@ public void testRemoveChannelsFromNameSpacedGroup() throws InterruptedException,
255255
}
256256

257257
@Test
258-
public void testGetAllChannelGroupNames() throws InterruptedException, JSONException, PubnubException {
258+
public void testGetAllChannelGroupNames() throws InterruptedException, JSONException {
259259
String group1 = "jtest_group1";
260260
String group2 = "jtest_group2";
261261

@@ -288,7 +288,7 @@ public void testGetAllChannelGroupNames() throws InterruptedException, JSONExcep
288288
}
289289

290290
@Test
291-
public void testGetAllChannelGroupNamesNamespace() throws InterruptedException, JSONException, PubnubException {
291+
public void testGetAllChannelGroupNamesNamespace() throws InterruptedException, JSONException {
292292
String group1 = "jtest_group1";
293293
String group2 = "jtest_group2";
294294

@@ -322,7 +322,7 @@ public void testGetAllChannelGroupNamesNamespace() throws InterruptedException,
322322
}
323323

324324
@Test
325-
public void testRemoveGroup() throws InterruptedException, JSONException, PubnubException {
325+
public void testRemoveGroup() throws InterruptedException, JSONException {
326326
String group = "jtest_group1";
327327
JSONObject result;
328328
JSONArray groups;
@@ -360,7 +360,7 @@ public void testRemoveGroup() throws InterruptedException, JSONException, Pubnub
360360
}
361361

362362
@Test
363-
public void testRemoveNamespacedGroup() throws InterruptedException, JSONException, PubnubException {
363+
public void testRemoveNamespacedGroup() throws InterruptedException, JSONException {
364364
String group = "jtest_group1";
365365
JSONObject result;
366366
JSONArray groups;
@@ -398,7 +398,7 @@ public void testRemoveNamespacedGroup() throws InterruptedException, JSONExcepti
398398
}
399399

400400
@AfterClass
401-
public static void tearDown() throws InterruptedException, JSONException, PubnubException {
401+
public static void tearDown() throws InterruptedException, JSONException {
402402
Pubnub pubnub = new Pubnub("demo", "demo");
403403
pubnub.setOrigin("dara24.devbuild");
404404
pubnub.setCacheBusting(false);

0 commit comments

Comments
 (0)