diff --git a/plugin/src/main/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParser.java b/plugin/src/main/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParser.java index 12a1ef4dbe6..605bb2a4d36 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParser.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParser.java @@ -136,16 +136,18 @@ public class ReportingAttachmentParser implements EmailAttachmentParser= 400) { + String body = response.body() != null ? response.body().utf8ToString() : null; throw new ElasticsearchException("Watch[{}] reporting[{}] Error when polling pdf from host[{}], port[{}], " + - "method[{}], path[{}], status[{}]", context.watch().id(), attachment.id(), request.host(), request.port(), - request.method(), request.path(), reportGenerationResponse.status()); + "method[{}], path[{}], status[{}], body[{}]", context.watch().id(), attachment.id(), request.host(), + request.port(), request.method(), request.path(), response.status(), body); } else if (response.status() == 200) { return new Attachment.Bytes(attachment.id(), BytesReference.toBytes(response.body()), response.contentType(), attachment.inline()); } else { + String body = response.body() != null ? response.body().utf8ToString() : null; String message = LoggerMessageFormat.format("", "Watch[{}] reporting[{}] Unexpected status code host[{}], port[{}], " + - "method[{}], path[{}], status[{}]", context.watch().id(), attachment.id(), request.host(), request.port(), - request.method(), request.path(), reportGenerationResponse.status()); + "method[{}], path[{}], status[{}], body[{}]", context.watch().id(), attachment.id(), request.host(), + request.port(), request.method(), request.path(), response.status(), body); throw new IllegalStateException(message); } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java b/plugin/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java index 17a629a200f..174be4df9d3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java @@ -240,9 +240,10 @@ public class ReportingAttachmentParserTests extends ESTestCase { } public void testPollingRequestIsError() throws Exception { + boolean hasBody = randomBoolean(); when(httpClient.execute(any(HttpRequest.class))) .thenReturn(new HttpResponse(200, "{\"path\":\"whatever\"}")) - .thenReturn(new HttpResponse(403)); + .thenReturn(new HttpResponse(403, hasBody ? "no permissions" : null)); ReportingAttachment attachment = new ReportingAttachment("foo", "http://www.example.org/", randomBoolean(), TimeValue.timeValueMillis(1), 10, null, null); @@ -250,6 +251,9 @@ public class ReportingAttachmentParserTests extends ESTestCase { ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> reportingAttachmentParser.toAttachment(createWatchExecutionContext(), Payload.EMPTY, attachment)); assertThat(e.getMessage(), containsString("Error when polling pdf")); + if (hasBody) { + assertThat(e.getMessage(), containsString("body[no permissions]")); + } } public void testPollingRequestRetryIsExceeded() throws Exception {