diff --git a/src/main/java/cokr/xit/foundation/web/WebClient.java b/src/main/java/cokr/xit/foundation/web/WebClient.java index 04df14d..03114fb 100644 --- a/src/main/java/cokr/xit/foundation/web/WebClient.java +++ b/src/main/java/cokr/xit/foundation/web/WebClient.java @@ -90,7 +90,7 @@ public class WebClient { conf.respHandler.accept(hresp); } } catch (Throwable e) { - throw Assert.runtimeException(e); + conf.errorHandler.accept(Assert.rootCause(e)); } } @@ -111,7 +111,7 @@ public class WebClient { conf.respHandler.accept(hresp); } } catch (Throwable e) { - throw Assert.runtimeException(e); + conf.errorHandler.accept(Assert.rootCause(e)); } } @@ -129,6 +129,9 @@ public class WebClient { System.out.println("status: " + hresp.statusCode()); System.out.println(hresp.body()); }; + private Consumer errorHandler = t -> { + System.out.println(t.getMessage()); + }; public Config header(String key, String value) { if (headers == null) @@ -169,6 +172,11 @@ public class WebClient { return this; } + public Config onError(Consumer handler) { + errorHandler = handler; + return this; + } + HttpRequest get() { String queryString = getParams(); if (!queryString.isEmpty())