Skip to content

Commit de45c12

Browse files
committed
Introduce new cancelled error type
1 parent 05f989a commit de45c12

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

library/src/main/java/me/proxer/library/api/ProxerCall.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ private ProxerException processNonProxerError(@NotNull final Throwable error) {
135135
if (error instanceof SocketTimeoutException) {
136136
return new ProxerException(ProxerException.ErrorType.TIMEOUT, error);
137137
} else if (error instanceof IOException) {
138-
return new ProxerException(ProxerException.ErrorType.IO, error);
138+
if (error.getMessage().equals("Canceled")) {
139+
return new ProxerException(ProxerException.ErrorType.CANCELLED, error);
140+
} else {
141+
return new ProxerException(ProxerException.ErrorType.IO, error);
142+
}
139143
} else if (error instanceof JsonDataException) {
140144
return new ProxerException(ProxerException.ErrorType.PARSING, error);
141145
} else {

library/src/main/java/me/proxer/library/api/ProxerException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public enum ErrorType {
100100
TIMEOUT,
101101
IO,
102102
PARSING,
103+
CANCELLED,
103104
UNKNOWN
104105
}
105106

library/src/test/java/me/proxer/library/api/ProxerCallTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ public void testInvalidDataError() throws IOException {
5858
"PARSING ErrorType"));
5959
}
6060

61+
@Test(timeout = 1000L)
62+
public void testCancelledError() throws IOException, InterruptedException {
63+
final CountDownLatch lock = new CountDownLatch(1);
64+
65+
server.enqueue(new MockResponse().setBody(fromResource("news.json")));
66+
67+
final ProxerCall<List<NewsArticle>> call = api.notifications().news().build();
68+
69+
call.enqueue(result -> {
70+
// Failed. The lock will never be counted down and timeout.
71+
}, exception -> {
72+
assertThat(exception.getErrorType()).isEqualTo(ErrorType.CANCELLED);
73+
74+
lock.countDown();
75+
});
76+
77+
call.cancel();
78+
lock.await();
79+
}
80+
6181
@Test
6282
public void testServerError() throws Exception {
6383
server.enqueue(new MockResponse().setBody(fromResource("conferences_error.json")));

0 commit comments

Comments
 (0)