Skip to content

Commit 4e91760

Browse files
committed
[1452] simplify MethodsCompletionException implementation
1 parent bd9c5e8 commit 4e91760

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
package com.slack.api.methods;
22

3-
import lombok.Data;
43
import lombok.EqualsAndHashCode;
5-
import lombok.extern.slf4j.Slf4j;
6-
7-
import java.io.IOException;
84

95
/**
106
* Wrapped exception holding the cause exception occurred in AsyncMethodsClient
117
*/
12-
@Data
13-
@Slf4j
14-
@EqualsAndHashCode(callSuper = false)
8+
@EqualsAndHashCode(callSuper = true)
159
public class MethodsCompletionException extends RuntimeException {
16-
17-
private final IOException ioException;
18-
private final SlackApiException slackApiException;
19-
private final Exception otherException;
20-
21-
public MethodsCompletionException(IOException ioException, SlackApiException slackApiException, Exception otherException) {
22-
this.ioException = ioException;
23-
this.slackApiException = slackApiException;
24-
this.otherException = otherException;
10+
public MethodsCompletionException(Exception cause) {
11+
super(cause);
2512
}
26-
2713
}

slack-api-client/src/main/java/com/slack/api/methods/impl/AsyncRateLimitExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private <T extends SlackApiResponse> T runWithoutQueue(
130130
return handleIOException(teamId, methodName, e);
131131
} catch (SlackApiException e) {
132132
logSlackApiException(teamId, methodName, e);
133-
throw new MethodsCompletionException(null, e, null);
133+
throw new MethodsCompletionException(e);
134134
}
135135
}
136136

@@ -171,7 +171,7 @@ private <T extends SlackApiResponse> T enqueueThenRun(
171171
if (e.getResponse().code() == 429) {
172172
return enqueueThenRun(messageId, teamId, methodName, params, methodsSupplier);
173173
}
174-
throw new MethodsCompletionException(null, e, null);
174+
throw new MethodsCompletionException(e);
175175
} catch (InterruptedException e) {
176176
log.error("Got an InterruptedException (error: {})", e.getMessage(), e);
177177
throw new RuntimeException(e);
@@ -180,12 +180,12 @@ private <T extends SlackApiResponse> T enqueueThenRun(
180180

181181
private static <T extends SlackApiTextResponse> T handleRuntimeException(String teamId, String methodName, RuntimeException e) {
182182
log.error("Got an exception while calling {} API (team: {}, error: {})", methodName, teamId, e.getMessage(), e);
183-
throw new MethodsCompletionException(null, null, e);
183+
throw new MethodsCompletionException(e);
184184
}
185185

186186
private static <T extends SlackApiTextResponse> T handleIOException(String teamId, String methodName, IOException e) {
187187
log.error("Failed to connect to {} API (team: {}, error: {})", methodName, teamId, e.getMessage(), e);
188-
throw new MethodsCompletionException(e, null, null);
188+
throw new MethodsCompletionException(e);
189189
}
190190

191191
private static void logSlackApiException(String teamId, String methodName, SlackApiException e) {

slack-api-client/src/test/java/test_locally/api/methods/EqualityTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public void test() {
2323
.message("")
2424
.build();
2525

26-
assertEquals(new MethodsCompletionException(null, null, null), new MethodsCompletionException(null, null, null));
27-
assertEquals(new SlackApiException(response, ""), new SlackApiException(response, ""));
26+
assertEquals(new MethodsCompletionException(new SlackApiException(response, "")), new MethodsCompletionException(new SlackApiException(response, "")));
2827
}
2928
}

slack-api-client/src/test/java/test_locally/api/methods/ExceptionsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import com.slack.api.methods.MethodsCompletionException;
44
import org.junit.Test;
55

6+
import java.io.IOException;
7+
8+
import static org.junit.Assert.assertEquals;
69
import static org.junit.Assert.assertNotNull;
710

811
public class ExceptionsTest {
912

1013
@Test
1114
public void createMethodsCompletionException() {
12-
MethodsCompletionException exception = new MethodsCompletionException(null, null, null);
15+
MethodsCompletionException exception = new MethodsCompletionException(new IOException("IO error"));
1316
assertNotNull(exception);
17+
assertEquals("IO error", exception.getMessage());
1418
}
1519
}

0 commit comments

Comments
 (0)