Skip to content
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

Error Response Body being discarded #476

Open
TCap103 opened this issue Mar 17, 2023 · 5 comments
Open

Error Response Body being discarded #476

TCap103 opened this issue Mar 17, 2023 · 5 comments
Assignees

Comments

@TCap103
Copy link

TCap103 commented Mar 17, 2023

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.

@ChuckCrawford
Copy link
Collaborator

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

@adamdecaf
Copy link

adamdecaf commented Apr 19, 2023

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 added a commit to moov-io/achgateway that referenced this issue Apr 21, 2023
@ChuckCrawford
Copy link
Collaborator

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

@ChuckCrawford
Copy link
Collaborator

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

@ChuckCrawford ChuckCrawford self-assigned this Dec 12, 2023
@pgalbavy-itrs
Copy link

pgalbavy-itrs commented Oct 9, 2024

I am using 1.8.0 and seeing the same, in my case I was letting payload.source be empty. I ended up using the debug flags and that's how I found out. My debug output (sorry for the formatting):

2024-10-09T08:28:14+01:00 DEBUG: cmd/root.go:215 cmd.sendEvent() > pagerduty: resp: "HTTP/1.1 400 Bad Request\r\nContent-Length: 112\r\nAccess-Control-Allow-Credentials: true\r\nAccess-Control-Allow-Origin: \r\nAccess-Control-Expose-Headers: \r\nCache-Control: max-age=0, private, must-revalidate\r\nConnection: keep-alive\r\nContent-Type: application/json; charset=utf-8\r\nDate: Wed, 09 Oct 2024 07:28:14 GMT\r\nServer: nginx\r\nVary: Origin\r\nX-Request-Id: F_y4NPcv--KfmZ4JitUC\r\n\r\n{\"errors\":[\"'payload.source' is missing or blank\"],\"message\":\"Event object is invalid\",\"status\":\"invalid event\"}"
...
Error: HTTP response failed with status code 400 and no JSON error object was present

The first line is the body dump of the response, the following line the content of err printed as a plain string.

Edit: I also tried unwrapping the error and got:

2024-10-09T08:34:06+01:00 DEBUG: cmd/root.go:218 cmd.sendEvent() > pagerduty: aerr: pagerduty.EventsAPIV2Error{StatusCode:0, APIError:pagerduty.NullEventsAPIV2ErrorObject{Valid:false, ErrorObject:pagerduty.EventsAPIV2ErrorObject{Status:"", Message:"", Errors:[]string(nil)}}, message:""}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants