From 05c323472fa2fba8afc1e8628593d00967c45bc8 Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 19 Oct 2023 18:00:24 +0200 Subject: [PATCH] return the entire http response using a method --- hcloud/client.go | 2 +- hcloud/error.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hcloud/client.go b/hcloud/client.go index 66520edc4..dd05c0eff 100644 --- a/hcloud/client.go +++ b/hcloud/client.go @@ -373,7 +373,7 @@ func errorFromResponse(resp *http.Response, body []byte) error { } hcErr := ErrorFromSchema(respBody.Error) - hcErr.HTTPStatusCode = resp.StatusCode + hcErr.response = resp return hcErr } diff --git a/hcloud/error.go b/hcloud/error.go index 91647f60d..53d8b7826 100644 --- a/hcloud/error.go +++ b/hcloud/error.go @@ -3,6 +3,7 @@ package hcloud import ( "fmt" "net" + "net/http" ) // ErrorCode represents an error code returned from the API. @@ -94,15 +95,19 @@ type Error struct { Code ErrorCode Message string Details interface{} - // HTTPStatusCode is the status code of the response that included the error. - // It can be converted to a user readable string using net/http.StatusText(). - HTTPStatusCode int + + response *http.Response } func (e Error) Error() string { return fmt.Sprintf("%s (%s)", e.Message, e.Code) } +// Response returns the error underlying HTTP response. +func (e Error) Response() *http.Response { + return e.response +} + // ErrorDetailsInvalidInput contains the details of an 'invalid_input' error. type ErrorDetailsInvalidInput struct { Fields []ErrorDetailsInvalidInputField