@@ -91,28 +91,37 @@ public HttpException(int statusCode, Throwable cause) {
91
91
}
92
92
93
93
/**
94
- * Return the response body content as a bean
94
+ * Return the response body content as a bean, or else null if body content doesn't exist.
95
95
*
96
96
* @param cls The type of bean to convert the response to
97
97
* @return The response as a bean
98
98
*/
99
99
public <T > T bean (Class <T > cls ) {
100
+ if (httpResponse == null ) {
101
+ return null ;
102
+ }
100
103
final BodyContent body = context .readErrorContent (responseAsBytes , httpResponse );
101
104
return context .readBean (cls , body );
102
105
}
103
106
104
107
/**
105
- * Return the response body content as a UTF8 string.
108
+ * Return the response body content as a UTF8 string, or else null if body content doesn't exist .
106
109
*/
107
110
public String bodyAsString () {
111
+ if (httpResponse == null ) {
112
+ return null ;
113
+ }
108
114
final BodyContent body = context .readErrorContent (responseAsBytes , httpResponse );
109
115
return new String (body .content (), StandardCharsets .UTF_8 );
110
116
}
111
117
112
- /**
113
- * Return the response body content as raw bytes.
118
+ /**
119
+ * Return the response body content as raw bytes, or else null if body content doesn't exist .
114
120
*/
115
121
public byte [] bodyAsBytes () {
122
+ if (httpResponse == null ) {
123
+ return null ;
124
+ }
116
125
final BodyContent body = context .readErrorContent (responseAsBytes , httpResponse );
117
126
return body .content ();
118
127
}
0 commit comments