Skip to content

Commit

Permalink
return the entire http response using a method
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Oct 19, 2023
1 parent 8de4cfa commit 05c3234
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 8 additions & 3 deletions hcloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hcloud
import (
"fmt"
"net"
"net/http"
)

// ErrorCode represents an error code returned from the API.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 05c3234

Please sign in to comment.