-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A JSONArray text must start with '[' at 1 [character 2 line 1] #31
Comments
After digging into the code and following the stack trace I found the error is originating from This is very random as public static void main(String[] args) throws NotifyEventException {
String routingKey = "ROUTING_KEY";
String dedupKey = "DEDUP_KEY";
PagerDutyEventsClient pagerDutyEventsClient = create();
JSONObject customDetails = new JSONObject();
customDetails.put("field", "value1");
customDetails.put("field2", "value2");
Payload payload = Payload.Builder.newBuilder()
.setSummary("This is an incident test to test PagerDutyEventsClient")
.setSource("testing host")
.setSeverity(Severity.INFO)
.setTimestamp(OffsetDateTime.now())
.setCustomDetails(customDetails)
.build();
List<ImageContext> imageContextList = new ArrayList<>();
imageContextList.add(new ImageContext("src1"));
List<LinkContext> linkContextList = new ArrayList<>();
linkContextList.add(new LinkContext("href", "text"));
TriggerIncident incident = TriggerIncident.TriggerIncidentBuilder
.newBuilder(routingKey, payload)
.setDedupKey(dedupKey)
.setClient("client")
.setClientUrl("https://monitoring.example.com")
.setLinks(linkContextList)
.setImages(imageContextList)
.build();
pagerDutyEventsClient.trigger(incident);
AcknowledgeIncident ack = AcknowledgeIncident.AcknowledgeIncidentBuilder
.newBuilder(routingKey, dedupKey)
.build();
pagerDutyEventsClient.acknowledge(ack);
ResolveIncident resolve = ResolveIncident.ResolveIncidentBuilder
.newBuilder(routingKey, dedupKey)
.build();
pagerDutyEventsClient.resolve(resolve);
ChangeEventPayload changeEventPayload = ChangeEventPayload.Builder.newBuilder()
.setSummary("This is an change event test to test PagerDutyEventsClient")
.setSource("testing host")
.setTimestamp(OffsetDateTime.now())
.setCustomDetails(customDetails)
.build();
ChangeEvent changeEvent = ChangeEvent.ChangeEventBuilder
.newBuilder(routingKey, changeEventPayload)
.setLinks(linkContextList)
.build();
pagerDutyEventsClient.trackChange(changeEvent);
} Line 80 in this is: ChangeEvent changeEvent = ChangeEvent.ChangeEventBuilder
.newBuilder(routingKey, changeEventPayload)
.setLinks(linkContextList)
.build(); So it appears that the error is caused with this static test class and not even our payload. |
So we updated the version to private EventResult notifyEvent(PagerDutyEvent event, String api, int retryCount) throws NotifyEventException {
try {
HttpRequestWithBody request = Unirest.post(api)
.header("Content-Type", "application/json")
.header("Accept", "application/json");
request.body(event);
HttpResponse<JsonNode> jsonResponse = request.asJson();
if (log.isDebugEnabled()) {
log.debug(IOUtils.toString(jsonResponse.getRawBody()));
// A reset, so we can get the contents from the body that were dumped in the log before
jsonResponse.getRawBody().reset();
}
int responseStatus = jsonResponse.getStatus();
switch(responseStatus) {
case HttpStatus.SC_OK:
case HttpStatus.SC_CREATED:
case HttpStatus.SC_ACCEPTED:
return EventResult.successEvent(JsonUtils.getPropertyValue(jsonResponse, "status"), JsonUtils.getPropertyValue(jsonResponse, "message"), JsonUtils.getPropertyValue(jsonResponse, "dedup_key"));
case HttpStatus.SC_BAD_REQUEST:
return EventResult.errorEvent(JsonUtils.getPropertyValue(jsonResponse, "status"), JsonUtils.getPropertyValue(jsonResponse, "message"), JsonUtils.getArrayValue(jsonResponse, "errors"));
case RATE_LIMIT_STATUS_CODE:
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
if (doRetries) {
return handleRetries(event, api, retryCount, jsonResponse, responseStatus);
} else {
return EventResult.errorEvent(String.valueOf(responseStatus), "", IOUtils.toString(jsonResponse.getRawBody()));
}
default:
return EventResult.errorEvent(String.valueOf(responseStatus), "", IOUtils.toString(jsonResponse.getRawBody()));
}
} catch (UnirestException | IOException e) {
throw new NotifyEventException(e);
}
} The stack does not show which line is causing it but i'm guessing its coming from |
same here |
Any update here? |
Version 3.0.8 works for me |
3.0.8 not working for me 🙁 |
Same here, in 3.1.2. Full trace:
any idea @dikhan? |
Probably an error in the Unirest HTTP client |
See Pull request #32 issue appears if payload isn't json but an error string |
@machajdik @DodoMorph @salml I am still getting this issue. |
We are using the client to submit a trigger using the following code:
The serialized incident as a json looks like this:
However, we are unexpectedly getting the following error:
Any ideas?
The text was updated successfully, but these errors were encountered: