File tree Expand file tree Collapse file tree
main/java/me/proxer/library/api
test/java/me/proxer/library/api Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ public enum ErrorType {
100100 TIMEOUT ,
101101 IO ,
102102 PARSING ,
103+ CANCELLED ,
103104 UNKNOWN
104105 }
105106
Original file line number Diff line number Diff 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" )));
You can’t perform that action at this time.
0 commit comments