Skip to content

Commit 0e815f0

Browse files
committed
Add support for DELETE requests
1 parent 4725092 commit 0e815f0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,19 @@ func (c *Client) Request(v interface{}, method, path string, data interface{}) e
111111

112112
// Status code 500 is a server error and means nothing can be done at this
113113
// point.
114-
if response.StatusCode == 500 {
114+
if response.StatusCode == http.StatusInternalServerError {
115115
return ErrUnexpectedResponse
116116
}
117+
118+
// Status code 204 is returned for successful DELETE requests. Don't try to
119+
// unmarshal the body: that would return errors.
120+
if response.StatusCode == http.StatusNoContent && response.ContentLength == 0 {
121+
return nil
122+
}
123+
117124
// Status codes 200 and 201 are indicative of being able to convert the
118125
// response body to the struct that was specified.
119-
if response.StatusCode == 200 || response.StatusCode == 201 {
126+
if response.StatusCode == http.StatusOK || response.StatusCode == http.StatusCreated {
120127
if err := json.Unmarshal(responseBody, &v); err != nil {
121128
return fmt.Errorf("could not decode response JSON, %s: %v", string(responseBody), err)
122129
}

0 commit comments

Comments
 (0)