Skip to content

Commit

Permalink
fix: improve error message format with correlation id
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed May 6, 2024
1 parent 94229eb commit 2893806
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
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

0 comments on commit 2893806

Please sign in to comment.