onError 추가

master
mjkhan21 1 year ago
parent 36031a2da7
commit bf9c98ef35

@ -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<Throwable> 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<Throwable> handler) {
errorHandler = handler;
return this;
}
HttpRequest get() {
String queryString = getParams();
if (!queryString.isEmpty())

Loading…
Cancel
Save