Skip to content
Commits on Source (4)
......@@ -3,7 +3,7 @@ include:
ref: 2.1.4
file: '/gitlab-ci-template.yml'
image: docker.io/library/golang:1.21.4@sha256:9baee0edab4139ae9b108fffabb8e2e98a67f0b259fd25283c2a084bd74fea0d
image: docker.io/library/golang:1.21.5@sha256:2ff79bcdaff74368a9fdcb06f6599e54a71caf520fd2357a55feddd504bcaffb
variables:
REPO_NAME: ${CI_SERVER_HOST}/${CI_PROJECT_PATH_SLUG}
......
......@@ -3,7 +3,7 @@ module hcloud-dynfw
go 1.19
require (
github.com/hetznercloud/hcloud-go v1.52.0
github.com/hetznercloud/hcloud-go v1.53.0
github.com/hetznercloud/hcloud-go/v2 v2.5.1
)
......
......@@ -286,8 +286,8 @@ func (c *Client) Do(r *http.Request, v interface{}) (*Response, error) {
return response, fmt.Errorf("hcloud: error reading response meta data: %s", err)
}
if resp.StatusCode >= 400 && resp.StatusCode <= 599 {
err = errorFromResponse(resp, body)
if response.StatusCode >= 400 && response.StatusCode <= 599 {
err = errorFromResponse(response, body)
if err == nil {
err = fmt.Errorf("hcloud: server responded with status code %d", resp.StatusCode)
} else if IsError(err, ErrorCodeConflict) {
......@@ -359,7 +359,7 @@ func dumpRequest(r *http.Request) ([]byte, error) {
return dumpReq, nil
}
func errorFromResponse(resp *http.Response, body []byte) error {
func errorFromResponse(resp *Response, body []byte) error {
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
return nil
}
......@@ -371,7 +371,10 @@ func errorFromResponse(resp *http.Response, body []byte) error {
if respBody.Error.Code == "" && respBody.Error.Message == "" {
return nil
}
return ErrorFromSchema(respBody.Error)
hcErr := ErrorFromSchema(respBody.Error)
hcErr.response = resp
return hcErr
}
// Response represents a response from the API. It embeds http.Response.
......
......@@ -94,12 +94,19 @@ type Error struct {
Code ErrorCode
Message string
Details interface{}
response *Response
}
func (e Error) Error() string {
return fmt.Sprintf("%s (%s)", e.Message, e.Code)
}
// Response returns the [Response] that contained the error if available.
func (e Error) Response() *Response {
return e.response
}
// ErrorDetailsInvalidInput contains the details of an 'invalid_input' error.
type ErrorDetailsInvalidInput struct {
Fields []ErrorDetailsInvalidInputField
......
......@@ -2,4 +2,4 @@
package hcloud
// Version is the library's version following Semantic Versioning.
const Version = "1.52.0" // x-release-please-version
const Version = "1.53.0" // x-release-please-version
......@@ -7,7 +7,7 @@ github.com/cespare/xxhash/v2
# github.com/golang/protobuf v1.5.3
## explicit; go 1.9
github.com/golang/protobuf/proto
# github.com/hetznercloud/hcloud-go v1.52.0
# github.com/hetznercloud/hcloud-go v1.53.0
## explicit; go 1.19
github.com/hetznercloud/hcloud-go/hcloud
github.com/hetznercloud/hcloud-go/hcloud/internal/instrumentation
......