Skip to content

Commit 84f9159

Browse files
committed
Improve javadoc for HttpException
1 parent ca89f8e commit 84f9159

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

client/src/main/java/io/avaje/http/client/HttpException.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,37 @@
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
*/
1343
public class HttpException extends RuntimeException {
1444

0 commit comments

Comments
 (0)