From 84e06747f5a84b66b0f11bd646943def40d9a649 Mon Sep 17 00:00:00 2001 From: "Jonas L." Date: Fri, 9 Aug 2024 15:01:48 +0200 Subject: [PATCH] fix: `invalid_input` API errors may not return details (#507) The create uploaded certificate endpoint may return the following error: ``` { "error": { "code": "invalid_input", "message": "certificate must use larger key size" } } ``` This change ensure that we do not get a json unmarshal error (unexpected end of json) while trying to parse a non-existing details data. (cherry picked from commit ca78af2af8acd375460c0f9705ea9d62d5ee1cc4) --- hcloud/schema/error.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hcloud/schema/error.go b/hcloud/schema/error.go index 2d5cf5dd..86a5455e 100644 --- a/hcloud/schema/error.go +++ b/hcloud/schema/error.go @@ -17,7 +17,7 @@ func (e *Error) UnmarshalJSON(data []byte) (err error) { if err = json.Unmarshal(data, alias); err != nil { return } - if e.Code == "invalid_input" { + if e.Code == "invalid_input" && len(e.DetailsRaw) > 0 { details := ErrorDetailsInvalidInput{} if err = json.Unmarshal(e.DetailsRaw, &details); err != nil { return