PagerDuty/go-pagerduty

Error Response Body being discarded

Opened this issue · 4 comments

When using ManageEventWithContext if there is a response error we only get the error code and the high level error message back. For example: "HTTP response failed with status code 400 and no JSON error object was present".

From inspecting with curl I know there actually is a detailed error message. It appears that the APIError that we're attempting to decode into in client.getErrorFromResponse expects the response.Body to have the json key error however the body is actually (in my test example): {"errors":["'payload.source' is missing or blank"],"message":"Event object is invalid","status":"invalid event"}

I do not know if doWithEndpoint's other usages suffer from the same issue, or actually match the currently implemented behavior as I do not use those flows.

Currently working around this by using the debug methods to decode the response properly in my own code.

@TCap103 : would you mind letting us know which API(s) you are working with that are returning an "errors" key?

I am seeing this when sending a v2 event and payload with ManageEventWithContext . See moov-io/achgateway#171 for our issue tracking this.

Code: https://github.com/moov-io/achgateway/blob/master/internal/alerting/pagerduty.go#L32

Edit: Should we use .CreateEventWithContext(ctx, event) instead of ManageEventWithContext? We're just looking to trigger pages for on-call staff.

Edit2: I'm seeing the DebugFlag options, but am not finding a response body or v2 error response. Is there a better option to get full details why a v2 event couldn't be created?

Sometimes I was able to get a Invalid routing key response in plain text (aka no JSON response object).

HTTP response with status code 400 does not contain Content-Type: application/json

@adamdecaf : did you see improvement here after the introduction of this PR into v1.6.0 and beyond?

Same for @TCap103 : did you see improvement here after the introduction of this PR into v1.6.0 and beyond?