Skip to content

Commit ab35de3

Browse files
Merge pull request #168 from jhjaggars/master
Bug 1872557: handle 201 response from upload
2 parents b7bc3df + 30a6e7a commit ab35de3

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pkg/insights/insightsclient/insightsclient.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -181,28 +181,27 @@ func (c *Client) Send(ctx context.Context, endpoint string, source Source) error
181181
}
182182
}()
183183

184-
switch resp.StatusCode {
185-
case http.StatusOK:
186-
counterRequestSend.WithLabelValues(c.metricsName, "200").Inc()
187-
case http.StatusAccepted:
188-
counterRequestSend.WithLabelValues(c.metricsName, "202").Inc()
189-
case http.StatusUnauthorized:
190-
counterRequestSend.WithLabelValues(c.metricsName, "401").Inc()
184+
counterRequestSend.WithLabelValues(c.metricsName, strconv.Itoa(resp.StatusCode)).Inc()
185+
186+
if resp.StatusCode == http.StatusUnauthorized {
191187
klog.V(2).Infof("gateway server %s returned 401, x-rh-insights-request-id=%s", resp.Request.URL, requestID)
192188
return authorizer.Error{Err: fmt.Errorf("your Red Hat account is not enabled for remote support or your token has expired")}
193-
case http.StatusForbidden:
194-
counterRequestSend.WithLabelValues(c.metricsName, "403").Inc()
189+
}
190+
191+
if resp.StatusCode == http.StatusForbidden {
195192
klog.V(2).Infof("gateway server %s returned 403, x-rh-insights-request-id=%s", resp.Request.URL, requestID)
196193
return authorizer.Error{Err: fmt.Errorf("your Red Hat account is not enabled for remote support")}
197-
case http.StatusBadRequest:
198-
counterRequestSend.WithLabelValues(c.metricsName, "400").Inc()
194+
}
195+
196+
if resp.StatusCode == http.StatusBadRequest {
199197
body, _ := ioutil.ReadAll(resp.Body)
200198
if len(body) > 1024 {
201199
body = body[:1024]
202200
}
203201
return fmt.Errorf("gateway server bad request: %s (request=%s): %s", resp.Request.URL, requestID, string(body))
204-
default:
205-
counterRequestSend.WithLabelValues(c.metricsName, strconv.Itoa(resp.StatusCode)).Inc()
202+
}
203+
204+
if resp.StatusCode >= 300 || resp.StatusCode < 200 {
206205
body, _ := ioutil.ReadAll(resp.Body)
207206
if len(body) > 1024 {
208207
body = body[:1024]

0 commit comments

Comments
 (0)