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

feat: include raw response bodies in APIErrors #237

Merged
merged 3 commits into from
Jan 19, 2023
Merged

Conversation

rainest
Copy link
Contributor

@rainest rainest commented Dec 2, 2022

This adds raw error response bodies to APIErrors. This is a breaking change, as it modifies the public kong.NewAPIError() function signature, adding a new raw []byte parameter for the raw body.

go-kong does not provide universal coverage of all Kong endpoints, and does not have rich error handling for all endpoints it does cover. Currently, go-kong reads the body of any admin API error response (consuming it, so nothing downstream can read it) and extracts the message field for inclusion in the APIError it returns. It is not possible to perform further parsing on error bodies if desired.

Adding the raw response allows downstream clients to handle their own error parsing, primarily for ad-hoc requests where downstream builds its own requests and runs it via a go-kong client. I think this is also necessary for further parsing inside go-kong (I don't think raw bodies were available to go-kong services either), but need to confirm.


This came up in the context of KIC handling POST /config requests. go-kong does not provide a service for /config and does not provide error parsing for it as such. message isn't useful for this endpoint because it's a compressed version of the more machine-readable fields field those error responses.

@rainest rainest force-pushed the feat/apierror-raw branch 3 times, most recently from 4583e41 to fcec49f Compare January 18, 2023 22:30
@rainest
Copy link
Contributor Author

rainest commented Jan 18, 2023

Undrafting this in prep for expected gateway changes in FTI-4366. Although the expected format still isn't set in stone, getting this into go-kong will let us iterate rapidly on future gateway changes, since we'll always have the raw response available.

@rainest rainest marked this pull request as ready for review January 18, 2023 22:33
@rainest rainest requested a review from a team as a code owner January 18, 2023 22:33
@rainest rainest enabled auto-merge (rebase) January 19, 2023 02:29
kong/error.go Outdated Show resolved Hide resolved
@rainest rainest merged commit e05a12f into main Jan 19, 2023
@rainest rainest deleted the feat/apierror-raw branch January 19, 2023 21:18
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

Successfully merging this pull request may close these issues.

3 participants