@@ -181,28 +181,27 @@ func (c *Client) Send(ctx context.Context, endpoint string, source Source) error
181
181
}
182
182
}()
183
183
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 {
191
187
klog .V (2 ).Infof ("gateway server %s returned 401, x-rh-insights-request-id=%s" , resp .Request .URL , requestID )
192
188
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 {
195
192
klog .V (2 ).Infof ("gateway server %s returned 403, x-rh-insights-request-id=%s" , resp .Request .URL , requestID )
196
193
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 {
199
197
body , _ := ioutil .ReadAll (resp .Body )
200
198
if len (body ) > 1024 {
201
199
body = body [:1024 ]
202
200
}
203
201
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 {
206
205
body , _ := ioutil .ReadAll (resp .Body )
207
206
if len (body ) > 1024 {
208
207
body = body [:1024 ]
0 commit comments