From 19d70d993a03d03f013f9a6310229b3d6d7d8448 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 9 Aug 2024 11:26:00 +0200 Subject: [PATCH] fix: `invalid_input` API errors may not return details 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 data. --- 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