Skip to content

Commit

Permalink
fix: body unmarshalling dependence on contentLen (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coffeeri authored Dec 13, 2023
1 parent 7fbe985 commit fd1413f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ func mapErrorListToError(errorList *ErrorList) (errs error) {
}

func unmarshalBody(resp *http.Response, into any) error {
if resp.ContentLength == 0 {
return nil
}
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

if len(bodyBytes) == 0 {
return nil
}
return json.Unmarshal(bodyBytes, into)
}

0 comments on commit fd1413f

Please sign in to comment.