From bf9c98ef359da23b460a82cf470171a47f0f1301 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 25 Jul 2023 14:14:55 +0900 Subject: [PATCH] =?UTF-8?q?onError=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cokr/xit/foundation/web/WebClient.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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())