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

fix: improve error message format with correlation id [Backport release-1.x] #431

Merged
merged 1 commit into from
May 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion hcloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (e Error) Error() string {
correlationID := resp.internalCorrelationID()
if correlationID != "" {
// For easier debugging, the error string contains the Correlation ID of the response.
return fmt.Sprintf("%s (%s) (Correlation ID: %s)", e.Message, e.Code, correlationID)
return fmt.Sprintf("%s (%s, %s)", e.Message, e.Code, correlationID)
}
}
return fmt.Sprintf("%s (%s)", e.Message, e.Code)
Expand Down
4 changes: 2 additions & 2 deletions hcloud/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestError_Error(t *testing.T) {
Header: func() http.Header {
headers := http.Header{}
// [http.Header] requires normalized header names, easiest to do by using the Set method
headers.Set("X-Correlation-ID", "foobar")
headers.Set("X-Correlation-ID", "d5064a1f0bb9de4b")
return headers
}(),
},
},
},
want: "Creating image failed because of an unknown error. (unknown_error) (Correlation ID: foobar)",
want: "Creating image failed because of an unknown error. (unknown_error, d5064a1f0bb9de4b)",
},
{
name: "internal server error without correlation id",
Expand Down
Loading