Commits

Bob Bergman  committed 7fda8f7

Fix "others" error callback to forward exceptions

  • Participants
  • Parent commits 6a6430c

Comments (0)

Files changed (1)

File src/main/java/com/atlassian/jira/rest/client/p3/internal/AbstractP3RestClient.java

  */
 public abstract class AbstractP3RestClient
 {
-    protected static final PromiseCallback<Response> ERROR_CALLBACK = new PromiseCallback<Response>()
+    protected static <T> PromiseCallback<Response> newErrorCallback(final SettableFuture<T> delegate)
     {
-        @Override
-        public void handle(Response value)
+        return new PromiseCallback<Response>()
         {
-            try {
-                final String body = value.getEntity();
-                final Collection<String> errorMessages = extractErrors(body);
-                throw new RestClientException(errorMessages);
-            } catch (JSONException e1) {
-                throw new RestClientException(e1);
-            }
-            catch (IOException e)
+            @Override
+            public void handle(Response value)
             {
-                throw new RestClientException(e);
+                try
+                {
+                    final String body = value.getEntity();
+                    final Collection<String> errorMessages = extractErrors(body);
+                    delegate.setException(new RestClientException(errorMessages));
+                }
+                catch (JSONException e)
+                {
+                    delegate.setException(new RestClientException(e));
+                }
+                catch (IOException e)
+                {
+                    delegate.setException(new RestClientException(e));
+                }
             }
-        }
-    };
+        };
+    }
 
     protected interface ResponseHandler<T>
     {
                 .ok(successCallback)
                 .on(404, notFoundCallback)
                 .created(successCallback)
-                .others(ERROR_CALLBACK);
+                .others(newErrorCallback(future));
         return toPromise(future);
     }
+
 	protected <T> Promise<T> callAndParse(ResponsePromise responsePromise, final JsonParser<?, T> parser) {
         return callAndParse(responsePromise, new ResponseHandler<T>()
         {
         });
 	}
 
-
 	protected Promise<Void> call(ResponsePromise responsePromise) {
         final SettableFuture<Void> future = SettableFuture.create();
         responsePromise.noContent(new PromiseCallback<Response>()
                 future.set(null);
             }
         })
-                .others(ERROR_CALLBACK);
+                .others(newErrorCallback(future));
         return toPromise(future);
 	}