@@ -109,32 +109,29 @@ func (c *Client) Request(v interface{}, method, path string, data interface{}) e
109
109
c .DebugLog .Printf ("HTTP RESPONSE: %s" , string (responseBody ))
110
110
}
111
111
112
- // Status code 500 is a server error and means nothing can be done at this
113
- // point.
114
- if response .StatusCode == http .StatusInternalServerError {
115
- return ErrUnexpectedResponse
116
- }
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
-
124
- // Status codes 200 and 201 are indicative of being able to convert the
125
- // response body to the struct that was specified.
126
- if response .StatusCode == http .StatusOK || response .StatusCode == http .StatusCreated {
112
+ switch response .StatusCode {
113
+ case http .StatusOK , http .StatusCreated :
114
+ // Status codes 200 and 201 are indicative of being able to convert the
115
+ // response body to the struct that was specified.
127
116
if err := json .Unmarshal (responseBody , & v ); err != nil {
128
117
return fmt .Errorf ("could not decode response JSON, %s: %v" , string (responseBody ), err )
129
118
}
130
119
return nil
131
- }
120
+ case http .StatusNoContent :
121
+ // Status code 204 is returned for successful DELETE requests. Don't try to
122
+ // unmarshal the body: that would return errors.
123
+ return nil
124
+ case http .StatusInternalServerError :
125
+ // Status code 500 is a server error and means nothing can be done at this
126
+ // point.
127
+ return ErrUnexpectedResponse
128
+ default :
129
+ // Anything else than a 200/201/204/500 should be a JSON error.
130
+ var errorResponse ErrorResponse
131
+ if err := json .Unmarshal (responseBody , & errorResponse ); err != nil {
132
+ return err
133
+ }
132
134
133
- // Anything else than a 200/201/500 should be a JSON error.
134
- var errorResponse ErrorResponse
135
- if err := json .Unmarshal (responseBody , & errorResponse ); err != nil {
136
- return err
135
+ return errorResponse
137
136
}
138
-
139
- return errorResponse
140
137
}
0 commit comments