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

add details in APIError.Error #400

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@
## Unreleased

- Added extract of `details` field in response when CRUD API fails to extract
details from Konnect APIs.
details from Konnect APIs, and include `details` field in return value of
`Error()` method in `APIError`.
[#399](https://github.com/Kong/go-kong/pull/399)
[#400](https://github.com/Kong/go-kong/pull/400)

## [v0.50.0]

Expand Down
5 changes: 4 additions & 1 deletion kong/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func NewAPIErrorWithRaw(code int, msg string, raw []byte) *APIError {
}

func (e *APIError) Error() string {
return fmt.Sprintf("HTTP status %d (message: %q)", e.httpCode, e.message)
if e.details == nil {
return fmt.Sprintf("HTTP status %d (message: %q)", e.httpCode, e.message)
}
return fmt.Sprintf("HTTP status %d (message: %q; details: %v)", e.httpCode, e.message, e.details)
}

// Code returns the HTTP status code for the error.
Expand Down
Loading