File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
client/src/main/java/io/avaje/http/client Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 88 * <p>
99 * Wraps an underlying HttpResponse with helper methods to get the response body
1010 * as string or as a bean.
11- * </p>
11+ *
12+ * <h3>Example catching HttpException</h3>
13+ * <pre>{@code
14+ *
15+ * try {
16+ * clientContext.request()
17+ * .path("hello/saveForm")
18+ * .formParam("email", "[email protected] ") 19+ * .formParam("url", "notAValidUrl")
20+ * .POST()
21+ * .asVoid();
22+ *
23+ * } catch (HttpException e) {
24+ *
25+ * // obtain the statusCode from the exception ...
26+ * int statusCode = e.getStatusCode());
27+ *
28+ * HttpResponse<?> httpResponse = e.getHttpResponse();
29+ *
30+ * // obtain the statusCode from httpResponse ...
31+ * int statusCode = httpResponse.statusCode();
32+ *
33+ * // convert error response body into a bean (typically Jackson/Gson)
34+ * final MyErrorBean errorResponse = e.bean(MyErrorBean.class);
35+ *
36+ * final Map<String, String> errorMap = errorResponse.getErrors();
37+ * assertThat(errorMap.get("url")).isEqualTo("must be a valid URL");
38+ * assertThat(errorMap.get("name")).isEqualTo("must not be null");
39+ * }
40+ *
41+ * }</pre>
1242 */
1343public class HttpException extends RuntimeException {
1444
You can’t perform that action at this time.
0 commit comments