Skip to content

Commit

Permalink
Will return the raw body if detail is empty (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Lasse Gaardsholt <[email protected]>

Signed-off-by: Lasse Gaardsholt <[email protected]>
  • Loading branch information
Gaardsholt authored Dec 23, 2022
1 parent f676841 commit f2cfa8e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions teams/AddMember.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)

Expand Down Expand Up @@ -32,12 +33,21 @@ func (c *TeamsClient) AddMember(TeamId int, lo TeamsAddMemberOptions) (*ListMemb
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

var target Error
decode := json.NewDecoder(r.Body)

err = decode.Decode(&target)
if err != nil {
return nil, err
}

if target.Detail == "" {
target.Detail = string(bodyBytes)
}

return &ListMembershipsResult{Error: &target}, fmt.Errorf("%s", target.Detail)
}

Expand Down

0 comments on commit f2cfa8e

Please sign in to comment.