Skip to content

Commit

Permalink
fix: invalid_input API errors may not return details [Backport rele…
Browse files Browse the repository at this point in the history
…ase-1.x] (#508)

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.

---
Backport ca78af2 from #507.

BEGIN_COMMIT_OVERRIDE
fix: `invalid_input` API errors may not return details
END_COMMIT_OVERRIDE

Co-authored-by: Jonas L. <[email protected]>
  • Loading branch information
github-actions[bot] and jooola authored Aug 9, 2024
1 parent be7345b commit bfa3803
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hcloud/schema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfa3803

Please sign in to comment.