@@ -109,32 +109,30 @@ 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
}
119
+
130
120
return nil
131
- }
121
+ case http .StatusNoContent :
122
+ // Status code 204 is returned for successful DELETE requests. Don't try to
123
+ // unmarshal the body: that would return errors.
124
+ return nil
125
+ case http .StatusInternalServerError :
126
+ // Status code 500 is a server error and means nothing can be done at this
127
+ // point.
128
+ return ErrUnexpectedResponse
129
+ default :
130
+ // Anything else than a 200/201/204/500 should be a JSON error.
131
+ var errorResponse ErrorResponse
132
+ if err := json .Unmarshal (responseBody , & errorResponse ); err != nil {
133
+ return err
134
+ }
132
135
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
136
+ return errorResponse
137
137
}
138
-
139
- return errorResponse
140
138
}
0 commit comments