diff --git a/http-client/client/src/main/java/io/avaje/http/client/HttpException.java b/http-client/client/src/main/java/io/avaje/http/client/HttpException.java index fe0fbdb3..0c830201 100644 --- a/http-client/client/src/main/java/io/avaje/http/client/HttpException.java +++ b/http-client/client/src/main/java/io/avaje/http/client/HttpException.java @@ -91,28 +91,37 @@ public HttpException(int statusCode, Throwable cause) { } /** - * Return the response body content as a bean + * Return the response body content as a bean, or else null if body content doesn't exist. * * @param cls The type of bean to convert the response to * @return The response as a bean */ public T bean(Class cls) { + if (httpResponse == null) { + return null; + } final BodyContent body = context.readErrorContent(responseAsBytes, httpResponse); return context.readBean(cls, body); } /** - * Return the response body content as a UTF8 string. + * Return the response body content as a UTF8 string, or else null if body content doesn't exist. */ public String bodyAsString() { + if (httpResponse == null) { + return null; + } final BodyContent body = context.readErrorContent(responseAsBytes, httpResponse); return new String(body.content(), StandardCharsets.UTF_8); } - /** - * Return the response body content as raw bytes. + /** + * Return the response body content as raw bytes, or else null if body content doesn't exist. */ public byte[] bodyAsBytes() { + if (httpResponse == null) { + return null; + } final BodyContent body = context.readErrorContent(responseAsBytes, httpResponse); return body.content(); }