protected static String getErrorMessage(ResponseBody body) throws IOException {
String bodyString = body.string();
- if (equals(MediaType.parse("application/json;charset=utf-8"), body.contentType())) {
+ if (equals(MediaType.parse("application/json;charset=utf-8"), body.contentType()) && !isNullOrEmpty(bodyString)) {
try {
return Stream.of(buildGson().fromJson(bodyString, Errors.class).errorData)
.map(e -> e.exceptionName + " " + e.message)
.extracting(e -> ((BitbucketServerException) e).getHttpStatus()).isEqualTo(404);
}
+ @Test
+ public void fail_validate_url_when_body_is_empty() {
+ server.enqueue(new MockResponse().setResponseCode(404).setBody(""));
+
+ String serverUrl = server.url("/").toString();
+ assertThatThrownBy(() -> underTest.validateUrl(serverUrl))
+ .isInstanceOf(BitbucketServerException.class)
+ .hasMessage("")
+ .extracting(e -> ((BitbucketServerException) e).getHttpStatus()).isEqualTo(404);
+ }
+
@Test
public void fail_validate_url_when_validate_url_return_non_json_payload() {
server.enqueue(new MockResponse().setResponseCode(400)